@@ -4,7 +4,6 @@ var fs = require('fs')
4
4
var path = require ( 'path' )
5
5
var program = require ( 'commander' )
6
6
var chalk = require ( 'chalk' )
7
- var rm = require ( 'rimraf' ) . sync
8
7
var home = require ( 'user-home' )
9
8
var webpack = require ( 'webpack' )
10
9
var webpackMerge = require ( 'webpack-merge' )
@@ -18,7 +17,7 @@ var CopyPlugin = require('copy-webpack-plugin')
18
17
var tildify = require ( 'tildify' )
19
18
var loaders = require ( '../lib/loaders' )
20
19
var logger = require ( '../lib/logger' )
21
- var createServer = require ( '../lib/server ' )
20
+ var run = require ( '../lib/run ' )
22
21
23
22
/**
24
23
* Usage.
@@ -301,37 +300,9 @@ if (!options.disableWebpackConfig) {
301
300
}
302
301
}
303
302
304
- try {
305
- var compiler = webpack ( webpackConfig )
306
- } catch ( err ) {
307
- if ( err . name === 'WebpackOptionsValidationError' ) {
308
- logger . fatal ( err . message )
309
- } else {
310
- throw err
311
- }
312
- }
313
-
314
303
checkEntryExists ( options . entry )
315
304
316
- if ( typeof options . run === 'function' ) {
317
- options . run ( webpackConfig , options )
318
- } else if ( options . watch ) {
319
- console . log ( '> Running in watch mode' )
320
- rm ( path . join ( options . dist , '*' ) )
321
- compiler . watch ( { } , ( err , stats ) => handleBuild ( err , stats , true ) )
322
- } else if ( production ) {
323
- console . log ( '> Creating an optimized production build:\n' )
324
- // remove dist files but keep that folder in production mode
325
- rm ( path . join ( options . dist , '*' ) )
326
- compiler . run ( handleBuild )
327
- } else {
328
- var server = createServer ( compiler , options )
329
-
330
- server . listen ( options . port , options . host )
331
- if ( options . open ) {
332
- require ( 'opn' ) ( `http://${ options . host } :${ options . port } ` )
333
- }
334
- }
305
+ run ( webpackConfig , options )
335
306
336
307
function checkEntryExists ( entry ) {
337
308
if ( ! fs . existsSync ( entry ) ) {
@@ -364,33 +335,6 @@ function getLibraryName (fileName) {
364
335
return fileName . replace ( / [ - _ . ] ( [ \w ] ) / , ( _ , p1 ) => p1 . toUpperCase ( ) )
365
336
}
366
337
367
- function handleBuild ( err , stats , watch ) {
368
- if ( watch ) {
369
- process . stdout . write ( '\x1Bc' )
370
- }
371
- if ( err ) {
372
- process . exitCode = 1
373
- return console . error ( err . stack )
374
- }
375
- if ( stats . hasErrors ( ) || stats . hasWarnings ( ) ) {
376
- process . exitCode = 1
377
- return console . error ( stats . toString ( 'errors-only' ) )
378
- }
379
- console . log ( stats . toString ( {
380
- chunks : false ,
381
- children : false ,
382
- modules : false ,
383
- colors : true
384
- } ) )
385
- console . log ( `\n${ chalk . bgGreen . black ( ' SUCCESS ' ) } Compiled successfully.\n` )
386
- if ( ! watch ) {
387
- console . log ( `The ${ chalk . cyan ( options . dist ) } folder is ready to be de
6D47
ployed.` )
388
- console . log ( `You may also serve it locally with a static server:\n` )
389
- console . log ( ` ${ chalk . yellow ( 'npm' ) } i -g serve` )
390
- console . log ( ` ${ chalk . yellow ( 'serve' ) } ${ options . dist } --single\n` )
391
- }
392
- }
393
-
394
338
function getFilenames ( options ) {
395
339
return Object . assign ( {
396
340
js : options . production ? '[name].[chunkhash:8].js' : '[name].js' ,
0 commit comments