关于uniapp 微信小程序代码过大进行压缩处理

关于uniapp 微信小程序代码过大进行压缩处理
  • 下载

    npm i uglifyjs-webpack-plugin;
    npm i terser-webpack-plugin
    
  • 在vue.config.js中

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
	configureWebpack: {
		plugins: [
			//(“en” 内置于 Moment 中,无法移除)
			new MomentLocalesPlugin({
				localesToKeep: ['zh-cn'],
			}),
			new TerserPlugin({
				terserOptions: {
				  compress: {
					drop_console: process.env.NODE_ENV === 'production', // 生产环境下移除console.log
					drop_debugger: process.env.NODE_ENV === 'production', // 移除debugger语句
				  },
				  output: {
					comments: false, // 移除所有注释
				  },
				},
				extractComments: false, // 不提取license注释到单独的文件
			  })
		],
		optimization: {
			minimizer: [new UglifyJsPlugin()],
		},
	},
}

你可能感兴趣的:(uni-app,微信小程序,小程序)