Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
fix: use custom terser-webpack-plugin setup
Browse files Browse the repository at this point in the history
Cherry-picked from and closes #131.
  • Loading branch information
IlyaSemenov committed Dec 4, 2018
1 parent a7d840c commit b39e817
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
53 changes: 46 additions & 7 deletions lib/webpack/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,55 @@ module.exports = (api, config, type) => {

// No need to minimize in server or dev mode
if (type === 'client' && !api.options.dev && api.config.minimize !== false) {
// TODO: is there a simpler way to pull default minimizer setup without copy/pasting it?
const defaulter = new webpack.WebpackOptionsDefaulter()
const minimizer = defaulter.defaults['optimization.minimizer'](
config.toConfig()
)
config.merge({
optimization: {
minimize: true,
minimizer: [
...minimizer,
{
apply(compiler) {
const TerserPlugin = require('terser-webpack-plugin')
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: config.get('devtool') !== false,
terserOptions: {
parse: {
// we want terser to parse ecma 8 code. However, we don't want it
// to apply any minfication 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,
// Disabled because of an issue with Uglify breaking seemingly valid code:
// https://github.com/facebook/create-react-app/issues/2376
// Pending further investigation:
// https://github.com/mishoo/UglifyJS2/issues/2011
comparisons: false,
// Disabled because of an issue with Terser breaking valid code:
// https://github.com/facebook/create-react-app/issues/5250
// Pending futher investigation:
// https://github.com/terser-js/terser/issues/120
// Fixed in terser 3.10.7 which is not yet pulled by terser-webpack-plugin
inline: 2
},
mangle: {
safari10: true
},
output: {
ecma: 5,
comments: false,
// Turned on because emoji and regex is not minified properly using default
// https://github.com/facebook/create-react-app/issues/2488
ascii_only: true // eslint-disable-line camelcase
}
}
}).apply(compiler)
}
},
{
apply(compiler) {
// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down Expand Up @@ -219,7 +258,7 @@ module.exports = (api, config, type) => {
applyLoaders(normalRule, false)

function applyLoaders(rule, modules) {
const sourceMap = !isProd
const sourceMap = config.get('devtool') !== false

if (extract) {
if (type === 'client') {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"register-service-worker": "^1.2.0",
"serialize-javascript": "^1.4.0",
"serve-static": "^1.13.2",
"terser-webpack-plugin": "^1.1.0",
"time-fix-plugin": "^2.0.4",
"url-loader": "^1.1.0",
"vue": "^2.5.16",
Expand Down

0 comments on commit b39e817

Please sign in to comment.