From 4ae079c87eef032ca63913f5d20733fa14063dc0 Mon Sep 17 00:00:00 2001 From: Veveue Date: Wed, 21 Nov 2018 09:29:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=89=93=E5=8C=85=E4=BC=98=E5=8C=96=20ugli?= =?UTF-8?q?fyjs-webpack-plugin=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去console,压缩,注释 --- docs/zh/config/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/zh/config/README.md b/docs/zh/config/README.md index 2790abdf09af..91ed2ad7fc1c 100644 --- a/docs/zh/config/README.md +++ b/docs/zh/config/README.md @@ -181,6 +181,34 @@ chainWebpack(config, { webpack }) { // 删除进度条插件 config.plugins.delete('progress'); } +``` +打包优化 [uglifyjs-webpack-plugin](https://webpack.docschina.org/plugins/uglifyjs-webpack-plugin/) 配置 +```js +chainWebpack(config, { webpack }) { + config.merge({ + plugin: { + install: { + plugin: require('uglifyjs-webpack-plugin'), + args: [{ + sourceMap: false, + uglifyOptions: { + compress: { + // 删除所有的 `console` 语句 + drop_console: true, + }, + output: { + // 最紧凑的输出 + beautify: false, + // 删除所有的注释 + comments: false, + }, + } + }] + } + } + }) +} + ``` ### theme From f2b8c9d87a01b5d118809736287423dbf477c759 Mon Sep 17 00:00:00 2001 From: Veveue Date: Wed, 21 Nov 2018 09:40:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=89=93=E5=8C=85=E4=BC=98=E5=8C=96=20ugli?= =?UTF-8?q?fyjs-webpack-plugin=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去console,压缩,注释 --- docs/config/README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/config/README.md b/docs/config/README.md index 6aab60a1c2c7..b27044a68dc1 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -182,7 +182,33 @@ chainWebpack(config, { webpack }) { config.plugins.delete('progress'); } ``` - +configure [uglifyjs-webpack-plugin](https://webpack.docschina.org/plugins/uglifyjs-webpack-plugin/) +```js +chainWebpack(config, { webpack }) { + config.merge({ + plugin: { + install: { + plugin: require('uglifyjs-webpack-plugin'), + args: [{ + sourceMap: false, + uglifyOptions: { + compress: { + // remove `console.*` + drop_console: true, + }, + output: { + // whether to actually beautify the output + beautify: false, + // remove all comments + comments: false, + }, + } + }] + } + } + }) +} +``` ### theme The configuration theme is actually equipped with the less variable. Support for both object and string types, the string needs to point to a file that returns the configuration.