@wbi/cli-service
Version:
local service for wb-cli projects
52 lines (47 loc) • 1.36 kB
JavaScript
/**
* 项目文件分析,分析统计数据
*/
const rm = require('rimraf')
const chalk = require('chalk')
const webpack = require('webpack')
const webpackConfig = require('./webpack.prod.config')()
const webpackMerge = require('webpack-merge')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const analyzerConfig = webpackMerge(webpackConfig, {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerHost: 'localhost',
analyzerPort: 7441, // 运行后的端口号
reportFilename: 'report.html',
defaultSizes: 'parsed',
openAnalyzer: true,
generateStatsFile: false,
statsFilename: 'stats.json',
statsOptions: null,
logLevel: 'info'
})
]
})
module.exports = function () {
console.log('Building for production...\n')
rm(webpackConfig.output.path, err => {
if (err) throw err
webpack(analyzerConfig, function (err, stats) {
if (err) throw err
process.stdout.write(stats.toString({
assets: false,
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n')
if (stats.hasErrors()) {
console.log(chalk.red(' Build failed with errors.\n'))
process.exit(1)
}
console.log('')
})
})
}