Skip to content

Commit

Permalink
feat(cli): setup terser webpack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mediremi authored and KaiVandivier committed Aug 23, 2022
1 parent 223b191 commit 2693258
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"fs-extra": "^8.1.0",
"gaze": "^1.1.3",
"handlebars": "^4.3.3",
"html-webpack-plugin": "^5.5.0",
"http-proxy": "^1.18.1",
"i18next-conv": "^9",
"i18next-scanner": "^2.10.3",
Expand All @@ -56,6 +57,7 @@
"parse-gitignore": "^1.0.1",
"react-dev-utils": "^12.0.0",
"styled-jsx": "^4.0.1",
"terser-webpack-plugin": "^5.3.1",
"webpack": "^5.41.1",
"workbox-build": "^6.1.5"
},
Expand All @@ -72,7 +74,6 @@
"testEnvironment": "node"
},
"devDependencies": {
"html-webpack-plugin": "^5.5.0",
"outdent": "^0.8.0"
}
}
26 changes: 26 additions & 0 deletions cli/src/lib/plugin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent')
const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath')
const TerserPlugin = require('terser-webpack-plugin')
const webpack = require('webpack')
const makeBabelConfig = require('../../../config/makeBabelConfig')
const getShellEnv = require('../shell/env')
Expand Down Expand Up @@ -88,6 +89,31 @@ module.exports = ({ env: webpackEnv, paths }) => {
? 'static/js/plugin-[name].[contenthash:8].chunk.js'
: 'static/js/plugin-[name].chunk.js',*/
},
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
// We want terser to parse ecma 8 code. However, we don't want it
// to apply any minification steps that turns valid ecma 5 code
// into invalid ecma 5 code. This is why the 'compress' and 'output'
// sections only apply transformations that are ecma 5 safe
// https://github.com/facebook/create-react-app/pull/4234
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
},
output: {
ecma: 5,
comments: false,
},
},
}),
],
},
plugins: [
new HtmlWebpackPlugin(
Object.assign(
Expand Down
21 changes: 12 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3043,14 +3043,6 @@
"@types/eslint" "*"
"@types/estree" "*"

"@types/eslint@*":
version "8.4.3"
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.4.3.tgz#5c92815a3838b1985c90034cd85f26f59d9d0ece"
integrity sha512-YP1S7YJRMPs+7KZKDb9G63n8YejIwW9BALq7a5j2+H4yl6iOv9CB29edho+cuFRrvmJbbaH2yiVChKLJVysDGw==
dependencies:
"@types/estree" "*"
"@types/json-schema" "*"

"@types/eslint@^7.28.2":
version "7.29.0"
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.29.0.tgz#e56ddc8e542815272720bb0b4ccc2aff9c3e1c78"
Expand Down Expand Up @@ -13403,7 +13395,18 @@ terminal-link@^2.0.0:
ansi-escapes "^4.2.1"
supports-hyperlinks "^2.0.0"

terser-webpack-plugin@^5.1.3, terser-webpack-plugin@^5.2.5:
terser-webpack-plugin@^5.1.3, terser-webpack-plugin@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.1.tgz#0320dcc270ad5372c1e8993fabbd927929773e54"
integrity sha512-GvlZdT6wPQKbDNW/GDQzZFg/j4vKU96yl2q6mcUkzKOgW4gwf1Z8cZToUCrz31XHlPWH8MVb1r2tFtdDtTGJ7g==
dependencies:
jest-worker "^27.4.5"
schema-utils "^3.1.1"
serialize-javascript "^6.0.0"
source-map "^0.6.1"
terser "^5.7.2"

terser-webpack-plugin@^5.2.5:
version "5.3.3"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.3.tgz#8033db876dd5875487213e87c627bca323e5ed90"
integrity sha512-Fx60G5HNYknNTNQnzQ1VePRuu89ZVYWfjRAeT5rITuCY/1b08s49e5kSQwHDirKZWuoKOBRFS98EUUoZ9kLEwQ==
Expand Down

0 comments on commit 2693258

Please sign in to comment.