@@ -168,64 +168,85 @@ class Compile extends Hook {
168
168
return initCompiler ( this , this . options . compilers ) ;
169
169
}
170
170
171
- start ( ) {
171
+ start ( files ) {
172
172
if ( this . running ) {
173
173
return ;
174
174
}
175
+
175
176
this . running = true ;
177
+ this . logger . info ( 'build' , 'start...' ) ;
178
+ let parseComps ;
179
+
180
+ if ( files === undefined || files . length === 0 ) {
181
+ // if files is empty, compile from entry
182
+ parseComps = this . hookUnique ( 'wepy-parser-wpy' ,
183
+ { path : this . options . entry , type : 'app' } ) . then ( app => {
184
+ let sfc = app . sfc ;
185
+ let script = sfc . script ;
186
+ let styles = sfc . styles ;
187
+ let config = sfc . config ;
188
+
189
+ let appConfig = config . parsed . output ;
190
+ if ( ! appConfig . pages || appConfig . pages . length === 0 ) {
191
+ appConfig . pages = [ ] ;
192
+ this . hookUnique ( 'error-handler' , {
193
+ type : 'warn' ,
194
+ ctx : app ,
195
+ message : `Missing "pages" in App config`
196
+ } ) ;
197
+ }
198
+ let pages = appConfig . pages . map ( v => {
199
+ return path . resolve ( app . file , '..' , v ) ;
200
+ } ) ;
176
201
177
- this . hookUnique ( 'wepy-parser-wpy' , { path : this . options . entry , type : 'app' } ) . then ( app => {
202
+ if ( appConfig . subPackages || appConfig . subpackages ) {
203
+ ( appConfig . subpackages || appConfig . subPackages ) . forEach ( sub => {
204
+ sub . pages . forEach ( v => {
205
+ pages . push ( path . resolve ( app . file , '../' + sub . root || '' , v ) ) ;
206
+ } ) ;
178
207
179
- let sfc = app . sfc ;
180
- let script = sfc . script ;
181
- let styles = sfc . styles ;
182
- let config = sfc . config ;
208
+ } ) ;
209
+ }
183
210
184
- let appConfig = config . parsed . output ;
185
- if ( ! appConfig . pages || appConfig . pages . length === 0 ) {
186
- appConfig . pages = [ ] ;
187
- this . hookUnique ( 'error-handler' , {
188
- type : 'warn' ,
189
- ctx : app ,
190
- message : `Missing "pages" in App config`
191
- } ) ;
192
- }
193
- let pages = appConfig . pages . map ( v => {
194
- return path . resolve ( app . file , '..' , v ) ;
195
- } ) ;
211
+ let tasks = pages . map ( v => {
212
+ let file ;
196
213
197
- if ( appConfig . subPackages || appConfig . subpackages ) {
198
- ( appConfig . subpackages || appConfig . subPackages ) . forEach ( sub => {
199
- sub . pages . forEach ( v => {
200
- pages . push ( path . resolve ( app . file , '../' + sub . root || '' , v ) ) ;
214
+ file = v + this . options . wpyExt ;
215
+ if ( fs . existsSync ( file ) ) {
216
+ return this . hookUnique ( 'wepy-parser-wpy' , { path : file , type : 'page' } ) ;
217
+ }
218
+ file = v + '.js' ;
219
+ if ( fs . existsSync ( file ) ) {
220
+ return this . hookUnique ( 'wepy-parser-component' , { path : file , type : 'page' , npm : false } ) ;
221
+ }
222
+ this . hookUnique ( 'error-handler' , {
223
+ type : 'error' ,
224
+ ctx : app ,
225
+ message : `Can not resolve page: ${ v } `
201
226
} ) ;
202
-
203
227
} ) ;
204
- }
205
-
206
- let tasks = pages . map ( v => {
207
- let file ;
208
228
209
- file = v + this . options . wpyExt ;
229
+ this . hookSeq ( 'build-app' , app ) ;
230
+ this . hookUnique ( 'output-app' , app ) ;
231
+ return Promise . all ( tasks ) ;
232
+ } )
233
+ } else {
234
+ // else just compile these
235
+ const tasks = files . map ( file => {
210
236
if ( fs . existsSync ( file ) ) {
211
237
return this . hookUnique ( 'wepy-parser-wpy' , { path : file , type : 'page' } ) ;
212
238
}
213
- file = v + '.js' ;
214
- if ( fs . existsSync ( file ) ) {
215
- return this . hookUnique ( 'wepy-parser-component' , { path : file , type : 'page' , npm : false } ) ;
216
- }
217
239
this . hookUnique ( 'error-handler' , {
218
240
type : 'error' ,
219
- ctx : app ,
220
- message : `Can not resolve page: ${ v } `
241
+ ctx : { } ,
242
+ message : `Can not resolve page: ${ file } `
221
243
} ) ;
222
244
} ) ;
223
245
224
- this . hookSeq ( 'build-app' , app ) ;
225
- this . hookUnique ( 'output-app' , app ) ;
226
- return Promise . all ( tasks ) ;
227
- } ) . then ( comps => {
246
+ parseComps = Promise . all ( tasks ) ;
247
+ }
228
248
249
+ parseComps . then ( comps => {
229
250
function buildComponents ( comps ) {
230
251
if ( ! comps ) {
231
252
return null ;
@@ -257,6 +278,7 @@ class Compile extends Hook {
257
278
return null ;
258
279
}
259
280
}
281
+
260
282
return buildComponents . bind ( this ) ( comps ) ;
261
283
} ) . then ( ( ) => {
262
284
let vendorData = this . hookSeq ( 'build-vendor' , { } ) ;
@@ -269,7 +291,7 @@ class Compile extends Hook {
269
291
} ) . then ( ( ) => {
270
292
this . hookSeq ( 'process-done' ) ;
271
293
this . running = false ;
272
- this . logger . info ( 'process finished' ) ;
294
+ this . logger . info ( 'build' , ' finished') ;
273
295
if ( this . options . watch ) {
274
296
this . logger . info ( 'watching...' ) ;
275
297
this . watch ( ) ;
@@ -320,7 +342,13 @@ class Compile extends Hook {
320
342
}
321
343
if ( involvedFile ) {
322
344
this . logger . silly ( 'watch' , `Watcher triggered by file changes: ${ absolutePath } ` ) ;
323
- this . start ( ) ;
345
+ if ( absolutePath !== this . options . entry &&
346
+ path . extname ( absolutePath ) === this . options . wpyExt ) {
347
+ // if changed file is wpyExt and is not entry, just compile it
348
+ this . start ( [ absolutePath ] ) ;
349
+ } else {
350
+ this . start ( ) ;
351
+ }
324
352
}
325
353
}
326
354
} )
@@ -432,4 +460,4 @@ exports = module.exports = (program) => {
432
460
let opt = parseOptions . convert ( program ) ;
433
461
434
462
return new Compile ( opt ) ;
435
- }
463
+ } ;
0 commit comments