From 1cdc25ff79d127ec2b4b042da1d59d3f4b1dbd7a Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 3 Sep 2018 20:59:11 +0200 Subject: [PATCH] Use terser for minification (#5083) Fixes #5021 --- build/webpack.js | 8 +++ .../npm/terser-webpack-plugin_vx.x.x.js | 60 +++++++++++++++++++ package.json | 1 + 3 files changed, 69 insertions(+) create mode 100644 flow-typed/npm/terser-webpack-plugin_vx.x.x.js diff --git a/build/webpack.js b/build/webpack.js index b2b4d7ab5c..746ceb622d 100644 --- a/build/webpack.js +++ b/build/webpack.js @@ -19,6 +19,7 @@ import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin' import { ReactLoadablePlugin } from './webpack/plugins/react-loadable-plugin' import {SERVER_DIRECTORY, NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST, DEFAULT_PAGES_DIR, REACT_LOADABLE_MANIFEST, CLIENT_STATIC_FILES_RUNTIME_WEBPACK, CLIENT_STATIC_FILES_RUNTIME_MAIN} from '../lib/constants' import AutoDllPlugin from 'autodll-webpack-plugin' +import TerserPlugin from 'terser-webpack-plugin' // The externals config makes sure that // on the server side when modules are @@ -81,6 +82,13 @@ function optimizationConfig ({dir, dev, isServer, totalPages}) { return config } + // Terser is a better uglifier + config.minimizer = [new TerserPlugin({ + parallel: true, + sourceMap: false, + cache: true + })] + // Only enabled in production // This logic will create a commons bundle // with modules that are used in 50% of all pages diff --git a/flow-typed/npm/terser-webpack-plugin_vx.x.x.js b/flow-typed/npm/terser-webpack-plugin_vx.x.x.js new file mode 100644 index 0000000000..84b88f2ecc --- /dev/null +++ b/flow-typed/npm/terser-webpack-plugin_vx.x.x.js @@ -0,0 +1,60 @@ +// flow-typed signature: 7f0a5671a6d757d5e9f880e207a37572 +// flow-typed version: <>/terser-webpack-plugin_v1.0.2/flow_v0.73.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'terser-webpack-plugin' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'terser-webpack-plugin' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'terser-webpack-plugin/dist/cjs' { + declare module.exports: any; +} + +declare module 'terser-webpack-plugin/dist/index' { + declare module.exports: any; +} + +declare module 'terser-webpack-plugin/dist/minify' { + declare module.exports: any; +} + +declare module 'terser-webpack-plugin/dist/TaskRunner' { + declare module.exports: any; +} + +declare module 'terser-webpack-plugin/dist/worker' { + declare module.exports: any; +} + +// Filename aliases +declare module 'terser-webpack-plugin/dist/cjs.js' { + declare module.exports: $Exports<'terser-webpack-plugin/dist/cjs'>; +} +declare module 'terser-webpack-plugin/dist/index.js' { + declare module.exports: $Exports<'terser-webpack-plugin/dist/index'>; +} +declare module 'terser-webpack-plugin/dist/minify.js' { + declare module.exports: $Exports<'terser-webpack-plugin/dist/minify'>; +} +declare module 'terser-webpack-plugin/dist/TaskRunner.js' { + declare module.exports: $Exports<'terser-webpack-plugin/dist/TaskRunner'>; +} +declare module 'terser-webpack-plugin/dist/worker.js' { + declare module.exports: $Exports<'terser-webpack-plugin/dist/worker'>; +} diff --git a/package.json b/package.json index 0fefb76518..e3aed895df 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "source-map": "0.5.7", "strip-ansi": "3.0.1", "styled-jsx": "3.0.3-canary.0", + "terser-webpack-plugin": "1.0.2", "unfetch": "3.0.0", "url": "0.11.0", "webpack": "4.17.1",