Skip to content

Commit 2f85ac8

Browse files
committed
chore(webpack): move initialization to build:before nuxt hook
1 parent a351720 commit 2f85ac8

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/module.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,32 @@ export default function NetlifyCmsModule(moduleOptions) {
3333
this.nuxt.hook("build:before", builder => {
3434
const bundleBuilder = builder.bundleBuilder;
3535

36+
const webpackConfig = getWebpackNetlifyConfig(
37+
WEBPACK_NETLIFY_COMPILER_NAME,
38+
this.options,
39+
config
40+
);
41+
42+
webpackConfig.plugins.push({
43+
apply(compiler) {
44+
compiler.hooks.emit.tapAsync("NetlifyCMSPlugin", (compilation, cb) => {
45+
const netlifyConfigYAML = toYAML(configManager.cmsConfig);
46+
compilation.assets[NETLIFY_CONFIG_FILE_NAME] = {
47+
source: () => netlifyConfigYAML,
48+
size: () => netlifyConfigYAML.length
49+
};
50+
cb();
51+
});
52+
}
53+
});
54+
55+
const netlifyCompiler = webpack(webpackConfig);
56+
3657
// This will be run just before webpack compiler starts
3758
this.nuxt.hook("build:compile", ({ name }) => {
3859
if (name !== WEBPACK_CLIENT_COMPILER_NAME) {
3960
return;
4061
}
41-
const webpackConfig = getWebpackNetlifyConfig(
42-
WEBPACK_NETLIFY_COMPILER_NAME,
43-
this.options,
44-
config
45-
);
46-
47-
webpackConfig.plugins.push({
48-
apply(compiler) {
49-
compiler.hooks.emit.tapAsync(
50-
"NetlifyCMSPlugin",
51-
(compilation, cb) => {
52-
const netlifyConfigYAML = toYAML(configManager.cmsConfig);
53-
compilation.assets[NETLIFY_CONFIG_FILE_NAME] = {
54-
source: () => netlifyConfigYAML,
55-
size: () => netlifyConfigYAML.length
56-
};
57-
cb();
58-
}
59-
);
60-
}
61-
});
62-
63-
const netlifyCompiler = webpack(webpackConfig);
6462

6563
// This will be run just after webpack compiler ends
6664
netlifyCompiler.hooks.done.tapAsync(

0 commit comments

Comments
 (0)