我遵循了很多有关如何减小捆绑包大小的教程,但是对捆绑包大小没有任何影响,我也不知道为什么。
每当我将一些新代码添加到webpack时,我的捆绑包大小都与以前相同。
(我的应用程序是使用vue cli 3 pwa插件,webpack等构建的)
如果我运行npm run build,则会得到以下输出:
webpack.config.js:
const path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const OfflinePlugin = require('offline-plugin');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WebpackChunkHash = require('webpack-chunk-hash');
const CompressionPlugin = require('compression-webpack-plugin');
if (process.env.NODE_ENV === 'production') {
module.exports.plugins = (module.exports.plugins || []).concat([
// or use push because it's faster
new webpack.DefinePlugin({
'process.env': {
'process.env.NODE_ENV': '"production"',
},
}),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
pure_getters: true,
unsafe: …Run Code Online (Sandbox Code Playgroud)