You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.3 KiB
JavaScript

2 months ago
const { DefinePlugin } = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
5 months ago
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
2 months ago
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
2 months ago
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://192.168.10.54:9100/v1',
changeOrigin: true,
pathRewrite: {
'^/api': '',
},
},
5 months ago
},
2 months ago
},
configureWebpack: {
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true, // 删除 console
},
},
}),
new CssMinimizerPlugin(),
],
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 20000, // 生成块的最小大小
maxSize: 500000, // 生成块的最大大小
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `npm.${packageName.replace('@', '')}`;
},
},
},
},
runtimeChunk: 'single',
},
plugins: [
new CompressionWebpackPlugin({
test: /\.(js|css|html|svg)$/, // 需要压缩的文件类型
threshold: 10240, // 资源超过10KB时压缩
deleteOriginalAssets: false, // 是否删除原始文件
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static', // 生成静态报告文件
openAnalyzer: false, // 打包后是否自动打开报告
}),
],
},
chainWebpack: config => {
// config.plugin('define').use(DefinePlugin, [
// {
// 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
// },
// ]);
2 months ago
// config.module
// .rule('images')
// .use('url-loader')
// .loader('url-loader')
// .tap(options => ({
// limit: 8192, // 图片小于8KB时转换为base64
// fallback: {
// loader: 'file-loader',
// options: {
// name: 'img/[name].[hash:8].[ext]',
// },
// },
// }));
2 months ago
},
};