@@ -30,9 +30,12 @@ export default function NetlifyCmsModule(moduleOptions) {
30
30
const config = configManager . config ;
31
31
32
32
// This will be called once when builder started
33
- this . nuxt . plugin ( "build" , builder => {
33
+ this . nuxt . hook ( "build:before " , builder => {
34
34
// 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
+ }
36
39
const webpackConfig = getWebpackNetlifyConfig (
37
40
WEBPACK_NETLIFY_COMPILER_NAME ,
38
41
this . options ,
@@ -54,18 +57,6 @@ export default function NetlifyCmsModule(moduleOptions) {
54
57
55
58
const netlifyCompiler = webpack ( webpackConfig ) ;
56
59
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
-
69
60
// This will be run just after webpack compiler ends
70
61
netlifyCompiler . plugin ( "done" , async stats => {
71
62
// Don't reload failed builds
@@ -77,8 +68,10 @@ export default function NetlifyCmsModule(moduleOptions) {
77
68
78
69
// in development
79
70
if ( this . options . dev ) {
71
+ // Use shared filesystem and cache
72
+ netlifyCompiler . outputFileSystem = builder . mfs ;
80
73
// Show a message inside console when the build is ready
81
- builder . plugin ( " compiled", async ( ) => {
74
+ this . nuxt . hook ( "build: compiled", async ( ) => {
82
75
debug ( `Serving on: ${ config . adminPath } ` ) ;
83
76
} ) ;
84
77
@@ -108,9 +101,30 @@ export default function NetlifyCmsModule(moduleOptions) {
108
101
}
109
102
110
103
// Stop webpack middleware on nuxt.close()
111
- this . nuxt . plugin ( "close" , async ( ) => {
104
+ this . nuxt . hook ( "close" , async ( ) => {
112
105
await this . nuxt . renderer . netlifyWebpackDevMiddleware . close ( ) ;
113
106
} ) ;
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
+ } ) ;
114
128
}
115
129
} ) ;
116
130
} ) ;
@@ -157,7 +171,7 @@ export default function NetlifyCmsModule(moduleOptions) {
157
171
this . nuxt . renderer . netlifyFileWatcher = fileWatcher ;
158
172
159
173
// Stop watching on nuxt.close()
160
- this . nuxt . plugin ( "close" , ( ) => {
174
+ this . nuxt . hook ( "close" , ( ) => {
161
175
this . nuxt . renderer . netlifyFileWatcher . close ( ) ;
162
176
} ) ;
163
177
} else {
@@ -171,8 +185,8 @@ export default function NetlifyCmsModule(moduleOptions) {
171
185
}
172
186
173
187
// 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 ( ) => {
176
190
await move (
177
191
join ( generator . distNuxtPath , config . adminPath ) . replace ( / \/ $ / , "" ) ,
178
192
join ( generator . distPath , config . adminPath ) . replace ( / \/ $ / , "" )
0 commit comments