Skip to content

Commit

Permalink
Chore: replaces UglifyJS with Terser (styleguidist#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
derz committed Oct 17, 2018
1 parent 4dd1a6f commit 52d3d58
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"acorn": "^6.0.2",
"acorn-jsx": "^5.0.0",
"ast-types": "^0.11.6",
"buble": "^0.19.4",
"buble": "0.19.4",
"classnames": "^2.2.6",
"clean-webpack-plugin": "^0.1.19",
"clipboard-copy": "^2.0.1",
Expand Down Expand Up @@ -83,9 +83,9 @@
"rewrite-imports": "1.2.0",
"to-ast": "^1.0.0",
"type-detect": "^4.0.8",
"uglifyjs-webpack-plugin": "1.2.7",
"unist-util-visit": "^1.4.0",
"walkes": "^0.2.1",
"terser-webpack-plugin": "^1.1.0",
"webpack-dev-server": "^2.11.2",
"webpack-merge": "^4.1.4"
},
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/__tests__/make-webpack-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ it('should return a development config', () => {
});
expect(config).not.toHaveProperty('optimization');
} else {
expect(plugins).not.toContain('UglifyJsPlugin');
expect(plugins).not.toContain('TerserPlugin');
}
});

Expand All @@ -59,9 +59,9 @@ it('should return a production config', () => {
expect(config).toMatchObject({
mode: env,
});
expect(getClasses(config.optimization.minimizer, 'UglifyJsPlugin')).toHaveLength(1);
expect(getClasses(config.optimization.minimizer, 'TerserPlugin')).toHaveLength(1);
} else {
expect(plugins).toContain('UglifyJsPlugin');
expect(plugins).toContain('TerserPlugin');
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/scripts/make-webpack-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniHtmlWebpackPlugin = require('mini-html-webpack-plugin');
const MiniHtmlWebpackTemplate = require('@vxna/mini-html-webpack-template');
const CleanWebpackPlugin = require('clean-webpack-plugin');
Expand Down Expand Up @@ -85,17 +85,17 @@ module.exports = function(config, env) {
],
});

const uglifier = new UglifyJSPlugin({
const uglifier = new TerserPlugin({
parallel: true,
cache: true,
uglifyOptions: {
terserOptions: {
ie8: false,
ecma: 5,
compress: {
keep_fnames: true,
warnings: false,
/*
* Disable reduce_funcs to keep UglifyJS from inlining
* Disable reduce_funcs to keep Terser from inlining
* Preact's VNode. If enabled, the 'new VNode()' is replaced
* with a anonymous 'function(){}', which is problematic for
* preact-compat, since it extends the VNode prototype to
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/utils/__tests__/mergeWebpackConfig.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mergeWebpackConfig from '../mergeWebpackConfig';

class UglifyJsPlugin {}
class TerserPlugin {}
class MyPlugin {}
class MiniHtmlWebpackPlugin {}

Expand All @@ -27,8 +27,8 @@ it('should ignore certain sections', () => {
});

it('should ignore certain Webpack plugins', () => {
const baseInstance = new UglifyJsPlugin();
const userInstance = new UglifyJsPlugin();
const baseInstance = new TerserPlugin();
const userInstance = new TerserPlugin();
const result = mergeWebpackConfig(
{
plugins: [baseInstance],
Expand All @@ -39,7 +39,7 @@ it('should ignore certain Webpack plugins', () => {
);
expect(result.plugins).toHaveLength(2);
expect(result.plugins[0]).toBe(baseInstance);
expect(result.plugins[0].constructor.name).toBe('UglifyJsPlugin');
expect(result.plugins[0].constructor.name).toBe('TerserPlugin');
expect(result.plugins[1].constructor.name).toBe('MyPlugin');
});

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/utils/mergeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const IGNORE_PLUGINS = [
'HtmlWebpackPlugin',
'OccurrenceOrderPlugin',
'DedupePlugin',
'UglifyJsPlugin',
'TerserPlugin',
'HotModuleReplacementPlugin',
];

Expand Down

0 comments on commit 52d3d58

Please sign in to comment.