-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2def616
commit fa5d49e
Showing
8 changed files
with
248 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,55 @@ | ||
#!/usr/bin/env node | ||
|
||
import { resolve } from 'path'; | ||
import { red, yellow } from 'chalk'; | ||
import open from 'open'; | ||
import webpack from 'webpack'; | ||
import program from 'commander'; | ||
import '../bootstrap'; | ||
import { pRequire } from '..'; | ||
import { pRequire, getContext } from '..'; | ||
|
||
program | ||
.option('-o, --open', 'open webpack visualizer report') | ||
.parse(process.argv); | ||
|
||
const context = getContext(); | ||
const appConfig = pRequire('config/packing'); | ||
const webpackConfig = pRequire('config/webpack.build.babel', {}, appConfig); | ||
|
||
const { | ||
path: { | ||
dist: { | ||
root: distRoot | ||
} | ||
}, | ||
visualizer: { | ||
enable: visualizerEnable, | ||
options: visualizerOptions | ||
} | ||
} = appConfig; | ||
|
||
webpack(webpackConfig, (err, stats) => { | ||
if (err) { | ||
console.log(err); | ||
} else if (stats.hasErrors()) { | ||
const message = red(`[错误]: 💔 Webpack 打包失败。\n${stats.compilation.errors}`); | ||
const message = red(`[build]: 💔 Webpack 打包失败。\n${stats.compilation.errors}`); | ||
console.log(message); | ||
// 让 jenkins 终止编译 | ||
process.exit(1); | ||
} else if (stats.hasWarnings()) { | ||
const message = yellow(`[警告]: ⚠️ Webpack 打包成功,请关注以下信息:\n${stats.compilation.warnings}`); | ||
const message = yellow(`[build]: ⚠️ Webpack 打包成功,请关注以下信息:\n${stats.compilation.warnings}`); | ||
console.log(yellow(message)); | ||
} else { | ||
console.log(stats.toString(stats)); | ||
console.log('[成功]:💚 Webpack 打包成功。'); | ||
console.log('[build]:💚 Webpack 打包成功。'); | ||
|
||
if (visualizerEnable) { | ||
const file = resolve(context, distRoot, 'stats.html'); | ||
const message = `[webpack-visualizer-plugin]: 模块报表已经生成,该报表可以指导优化输出文件体积\n请运行 open file://${file} 查看报表`; | ||
console.log(message); | ||
if (program.open || visualizerOptions.open) { | ||
open(`file://${file}`); | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.