Skip to content

Commit

Permalink
feat: terser压缩js
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alfred committed Oct 19, 2020
1 parent 15040b2 commit 9669f8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 11 additions & 2 deletions config/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const TerserPlugin = require('terser-webpack-plugin');

module.exports = merge(common, {
mode: 'production',
Expand All @@ -10,7 +10,16 @@ module.exports = merge(common, {
],
devtool: 'source-map',
optimization: {
minimizer: [],
minimizer: [
new TerserPlugin({
// cache: true,
parallel: true,
// sourceMap: true, // 如果在生产环境中使用 source-maps,必须设置为 true
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
}
})
],
splitChunks: {
cacheGroups: {
common: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"babel-loader": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"html-webpack-plugin": "^4.5.0",
"terser-webpack-plugin": "^5.0.0",
"webpack": "^5.1.2",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^3.11.0",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4199,7 +4199,7 @@ pkg-dir@^3.0.0:

pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.npm.taobao.org/pkg-dir/download/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
resolved "https://registry.npm.taobao.org/pkg-dir/download/pkg-dir-4.2.0.tgz?cache=0&sync_timestamp=1602859056682&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fpkg-dir%2Fdownload%2Fpkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
dependencies:
find-up "^4.0.0"

Expand Down Expand Up @@ -5562,8 +5562,8 @@ webpack-sources@^2.0.1:
source-map "^0.6.1"

webpack@^5.1.2:
version "5.1.2"
resolved "https://registry.npm.taobao.org/webpack/download/webpack-5.1.2.tgz?cache=0&sync_timestamp=1602785870964&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fwebpack%2Fdownload%2Fwebpack-5.1.2.tgz#00146bb721119398ecf903b38ee4fda1a81593e1"
version "5.1.3"
resolved "https://registry.npm.taobao.org/webpack/download/webpack-5.1.3.tgz#a6e4fd250ef2513f94844ae5d8f7570215a2ac49"
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.45"
Expand Down

0 comments on commit 9669f8a

Please sign in to comment.