Skip to content

Commit

Permalink
feat: 新增terser-webpack-plugin插件build时移除console等多余代码
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Dec 31, 2020
1 parent 02e20df commit 15582c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"vue-template-compiler": "2.6.11",
"vuedraggable": "^2.23.2",
"webpack": "^4.35.3",
"webpack-bundle-analyzer": "^3.3.2"
"webpack-bundle-analyzer": "^3.3.2",
"terser-webpack-plugin": "^1.2.4"
},
"husky": {
"hooks": {
Expand Down
27 changes: 20 additions & 7 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @Date: 2020年10月28 10:44:39
*/
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');

function resolve(dir) {
Expand Down Expand Up @@ -50,12 +51,24 @@ module.exports = {
.loader('svgo-loader')
.end();
},
configureWebpack: {
resolve: {
alias: {
'@': resolve('src'),
packages: resolve('packages'),
},
},
configureWebpack: (config) => {
config.resolve.alias['@'] = resolve('src');
config.resolve.alias.packages = resolve('packages');
const plugins = [
new TerserPlugin({
terserOptions: {
compress: {
warnings: false,
drop_debugger: false,
drop_console: true,
},
},
sourceMap: false,
parallel: true,
}),
];
if (process.env.NODE_ENV !== 'development') {
config.plugins = [...config.plugins, ...plugins];
}
},
};

0 comments on commit 15582c5

Please sign in to comment.