@@ -30,9 +30,12 @@ export default function NetlifyCmsModule(moduleOptions) {
3030 const config = configManager . config ;
3131
3232 // This will be called once when builder started
33- this . nuxt . plugin ( "build" , builder => {
33+ this . nuxt . hook ( "build:before " , builder => {
3434 // This will be run just before webpack compiler starts
35- builder . plugin ( "compile" , ( { builder, compiler } ) => {
35+ this . nuxt . hook ( "build:compile" , ( { name } ) => {
36+ if ( name !== WEBPACK_CLIENT_COMPILER_NAME ) {
37+ return ;
38+ }
3639 const webpackConfig = getWebpackNetlifyConfig (
3740 WEBPACK_NETLIFY_COMPILER_NAME ,
3841 this . options ,
@@ -54,18 +57,6 @@ export default function NetlifyCmsModule(moduleOptions) {
5457
5558 const netlifyCompiler = webpack ( webpackConfig ) ;
5659
57- // Only add the compiler in production,
58- // in dev watch will be started by dev-middleware
59- if ( ! this . options . dev ) {
60- compiler . compilers . push ( netlifyCompiler ) ;
61- compiler [ netlifyCompiler . name ] = netlifyCompiler ;
62- }
63-
64- // Use shared filesystem and cache
65- const clientCompiler = compiler [ WEBPACK_CLIENT_COMPILER_NAME ] ;
66- netlifyCompiler . outputFileSystem = clientCompiler . outputFileSystem ;
67- netlifyCompiler . cache = clientCompiler . cache ;
68-
6960 // This will be run just after webpack compiler ends
7061 netlifyCompiler . plugin ( "done" , async stats => {
7162 // Don't reload failed builds
@@ -77,8 +68,10 @@ export default function NetlifyCmsModule(moduleOptions) {
7768
7869 // in development
7970 if ( this . options . dev ) {
71+ // Use shared filesystem and cache
72+ netlifyCompiler . outputFileSystem = builder . mfs ;
8073 // Show a message inside console when the build is ready
81- builder . plugin ( " compiled", async ( ) => {
74+ this . nuxt . hook ( "build: compiled", async ( ) => {
8275 debug ( `Serving on: ${ config . adminPath } ` ) ;
8376 } ) ;
8477
@@ -108,9 +101,30 @@ export default function NetlifyCmsModule(moduleOptions) {
108101 }
109102
110103 // Stop webpack middleware on nuxt.close()
111- this . nuxt . plugin ( "close" , async ( ) => {
104+ this . nuxt . hook ( "close" , async ( ) => {
112105 await this . nuxt . renderer . netlifyWebpackDevMiddleware . close ( ) ;
113106 } ) ;
107+ } else {
108+ // Only run the compiler in production,
109+ // in dev build is started by dev-middleware hooked to client webpack compiler
110+ this . nuxt . hook ( "build:done" , async ( ) => {
111+ await new Promise ( ( resolve , reject ) => {
112+ netlifyCompiler . run ( ( err , stats ) => {
113+ /* istanbul ignore next */
114+ if ( err ) {
115+ return reject ( err ) ;
116+ } else if ( stats . hasErrors ( ) ) {
117+ if ( this . options . test ) {
118+ err = stats . toString ( this . options . build . stats ) ;
119+ }
120+
121+ return reject ( err ) ;
122+ }
123+
124+ resolve ( ) ;
125+ } ) ;
126+ } ) ;
127+ } ) ;
114128 }
115129 } ) ;
116130 } ) ;
@@ -157,7 +171,7 @@ export default function NetlifyCmsModule(moduleOptions) {
157171 this . nuxt . renderer . netlifyFileWatcher = fileWatcher ;
158172
159173 // Stop watching on nuxt.close()
160- this . nuxt . plugin ( "close" , ( ) => {
174+ this . nuxt . hook ( "close" , ( ) => {
161175 this . nuxt . renderer . netlifyFileWatcher . close ( ) ;
162176 } ) ;
163177 } else {
@@ -171,8 +185,8 @@ export default function NetlifyCmsModule(moduleOptions) {
171185 }
172186
173187 // Move cms folder from `dist/_nuxt` folder to `dist/` after nuxt generate
174- this . nuxt . plugin ( "generator ", generator => {
175- generator . plugin ( "generate" , async ( ) => {
188+ this . nuxt . hook ( "generate ", generator => {
189+ generator . hook ( "generate" , async ( ) => {
176190 await move (
177191 join ( generator . distNuxtPath , config . adminPath ) . replace ( / \/ $ / , "" ) ,
178192 join ( generator . distPath , config . adminPath ) . replace ( / \/ $ / , "" )
0 commit comments