在根目录创建 vue.config.js 文件;安装依赖 npm install --save-dev @intervolga/optimize-cssnano-plugin
vue.config.js 如下:
const OptimizeCssnanoPlugin = require('@intervolga/optimize-cssnano-plugin'); module.exports = { configureWebpack: config => { if (process.env.NODE_ENV === 'development') { config.plugins.splice(4, 0, new OptimizeCssnanoPlugin({ cssnanoOptions: { preset: ['default', { discardComments: { removeAll: true, }, }], }, })) } } };
需要在 '@intervolga/optimize-cssnano-plugin' 中把 .css 改为 .wxss
https://github.com/intervolga/optimize-cssnano-plugin
uni-app使用的webpack版本应该是 webpack@^4.0.0