11'use strict' ;
22
3- const ora = require ( 'ora' ) ;
43const chalk = require ( 'chalk' ) ;
4+ const webpackAdapter = require ( '../../src/adapter' ) ;
55
66module . exports = function buildCommand ( api , opts ) {
77
@@ -29,6 +29,7 @@ module.exports = function buildCommand(api, opts) {
2929 options : {
3030 '-' : 'default webpack.' ,
3131 '-t <type>' : 'adapter type, eg. [ webpack, vusion ].' ,
32+ '--progress' : 'show how progress is reported during a compilation.' ,
3233 } ,
3334 details : `
3435Examples:
@@ -38,60 +39,26 @@ Examples:
3839 } , args => {
3940 process . env . NODE_ENV = process . env . NODE_ENV || 'production' ;
4041 const type = args . t || 'webpack' ;
41- return runServe ( api , type ) ;
42+ const progress = args . progress ;
43+ return runBuild ( api , { type, progress } ) ;
4244 } ) ;
4345} ;
4446
45- function runServe ( api , type ) {
47+ function runBuild ( api , { type, progress } ) {
4648 const logger = api . logger ;
47- const webpackConfig = api . getState ( 'webpackConfig' ) ;
48-
49- let webpackCompiler ;
50- let webpackDevOptions ;
51-
52- if ( type === 'vusion' ) {
53- const vusionAdapter = require ( '../../src/adapter/vusion' ) ( webpackConfig , false , {
54- modifyDefaultVusionConfig ( vusionConfig ) {
55- return api . applyPluginHooks ( 'modifyDefaultVusionConfig' , vusionConfig ) ;
56- } ,
57- resolveVusionConfig ( vusionConfig ) {
58- return api . applyPluginHooks ( 'modifyVusionConfig' , vusionConfig ) ;
59- } ,
60- resolveVusionWebpackConfig ( vusionWebpackConfig ) {
61- return api . applyPluginHooks ( 'modifyVusionWebpackConfig' , vusionWebpackConfig ) ;
62- } ,
63- } ) ;
64- webpackCompiler = vusionAdapter . compiler ;
65- webpackDevOptions = vusionAdapter . devOptions || { } ;
66- } else {
67- const webpackAdapter = require ( '../../src/adapter/webpack' ) ( webpackConfig , false ) ;
68- if ( webpackAdapter ) {
69- webpackCompiler = webpackAdapter . compiler ;
70- webpackDevOptions = webpackAdapter . devOptions || { } ;
71- }
72- }
7349
7450 // [ 'post', 'host', 'contentBase', 'entrys', 'hooks' ]; // serverConfig
7551 const info = {
7652 type,
7753 config : api . config ,
7854 serverConfig : api . serverConfig ,
79- onlyNode : false ,
80- webpackConfig,
8155 } ;
8256
83- // 更新一次
84- api . setState ( 'webpackConfig' , webpackConfig ) ;
85-
86- const { compiler, devOptions = { } } = api . applyPluginHooks ( 'modifyWebpackCompiler' , {
87- type,
88- webpackConfig,
89- compiler : webpackCompiler ,
90- devOptions : webpackDevOptions ,
91- } ) ;
57+ const { compiler, devOptions, webpackConfig } = webpackAdapter ( api , { type, isDev : false , progress } ) ;
9258
9359 info . compiler = compiler ;
9460 info . devOptions = devOptions ;
61+ info . webpackConfig = webpackConfig ;
9562
9663 return new Promise ( ( resolve , reject ) => {
9764 const spinner = logger . spinner ( 'Building for production...' ) ;
@@ -106,13 +73,13 @@ function runServe(api, type) {
10673 return reject ( err ) ;
10774 }
10875
109- process . stdout . write ( stats . toString ( {
76+ process . stdout . write ( stats . toString ( Object . assign ( {
11077 colors : true ,
11178 modules : false ,
11279 children : false ,
11380 chunks : false ,
11481 chunkModules : false ,
115- } ) + '\n' ) ;
82+ } , webpackConfig . stats || { } ) ) + '\n' ) ;
11683
11784 api . applyPluginHooks ( 'onBuildSuccess' , stats ) ;
11885 // 处理完成
0 commit comments