3 Star 1 Fork 1

牛气腾腾/webpack5-vue2-element2-template

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
webpack.prod.config.js 2.87 KB
一键复制 编辑 原始数据 按行查看 历史
Yakima 提交于 4年前 . remove redundant code
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpackBaseConfig = require('./webpack.base.config');
const { toProjectRoot, isAnalyze } = require('./utils');
webpackBaseConfig.mode = 'production';
webpackBaseConfig.optimization = {
runtimeChunk: {
name: 'runtime',
},
moduleIds: 'deterministic',
minimize: true,
minimizer: [
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
`...`,
new CssMinimizerPlugin({
parallel: true,
}),
new TerserPlugin({
include: [toProjectRoot('/src')],
exclude: [/\/node_modules/],
// default parallel nums:os.cpus().length - 1
parallel: true,
terserOptions: {
ecma: 5,
sourceMap: false,
},
}),
],
splitChunks: {
chunks: 'async',
minSize: 20000,
minRemainingSize: 0,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
};
webpackBaseConfig.module.rules = webpackBaseConfig.module.rules.concat([
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: false,
},
},
'postcss-loader',
],
include: [/node_modules[\\/]element-ui/, toProjectRoot('/src')],
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: false,
},
},
'postcss-loader',
{
loader: 'sass-loader',
options: {
sourceMap: false,
},
},
],
include: [/node_modules[\\/]element-ui/, toProjectRoot('/src')],
},
]);
webpackBaseConfig.plugins = webpackBaseConfig.plugins.concat(
[
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:8].css',
}),
isAnalyze && new BundleAnalyzerPlugin(),
].filter(Boolean)
);
module.exports = webpackBaseConfig;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/bulls-cows/webpack5-vue2-element2-template.git
git@gitee.com:bulls-cows/webpack5-vue2-element2-template.git
bulls-cows
webpack5-vue2-element2-template
webpack5-vue2-element2-template
master

搜索帮助