cyb-cli
Version:
塞伯坦CYB-CLI是面向前端模块化工程的构建工具。主要目的是帮助开发者统一前端开发模式和项目开发结构,提高功能扩展和降低维护成本,自动化前端工作流,提高开发效率和开发质量。
80 lines (77 loc) • 2.29 kB
JavaScript
/**
* =================================
* @2018 塞伯坦-CYB前端模块化工程构建工具
* https://github.com/jd-cyb/cyb-cli
* =================================
*/
const webpack = require('webpack')
const path = require('path')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const safeParser = require('postcss-safe-parser')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const outputPath = require('./output-path')
const config = require('../fezconfig')
module.exports = {
mode: 'production',
output: {
path: outputPath.dist(),
filename: '[name].[chunkhash:8].js',
chunkFilename: path.join(outputPath.js(), '[name].[chunkhash:8].js')
},
module: {
rules: [...(config.useMock.dist ? [{
test: /\.(js|jsx|ts)$/,
exclude: /(node_modules|bower_components)/,
use: [{
loader: 'fez-preprocess-loader',
options: {
available: !config.useMock.dist
}
}]
}] : [])]
},
optimization: {
runtimeChunk: {
name: path.join(outputPath.js(), 'manifest')
},
splitChunks: {
cacheGroups: {
vendors: {
name: `vendor-webpack`,
test: /[\\/]node_modules[\\/]/,
priority: -10,
chunks: 'initial'
},
common: {
name: `common-webpack`,
minChunks: 2,
priority: -20,
chunks: 'initial',
reuseExistingChunk: true
}
}
}
},
plugins: [
new ProgressBarPlugin(),
//压缩css
new OptimizeCSSPlugin({
cssProcessorOptions: {
parser: safeParser,
discardComments: {
removeAll: true
}
}
}),
//webpack打包档案分析
...(config.webpack.analyzer.available ? [new BundleAnalyzerPlugin(config.webpack.options)] : []),
new webpack.BannerPlugin('@2018 塞伯坦-CYB前端模块化工程构建工具\nhttps://github.com/jd-cyb/cyb-cli'),
// 根据模块的相对路径生成一个四位数的hash作为模块id
new webpack.HashedModuleIdsPlugin({
hashDigest: 'hex'
}),
// enable scope hoisting
new webpack.optimize.ModuleConcatenationPlugin()
]
}