diff --git a/package.json b/package.json index 354f8e9..b3e6353 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "sass-loader": "^7.0.1", "style-loader": "^0.23.0", "svg-sprite-loader": "^4.1.2", - "uglifyjs-webpack-plugin": "^2.0.1", + "terser-webpack-plugin": "^1.1.0", "webpack": "4.23.1", "webpack-bundle-analyzer": "^3.0.3", "webpack-cli": "^3.1.2", diff --git a/webpack.common.js b/webpack.common.js index bd1d79b..40e9a9d 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -160,14 +160,6 @@ module.exports.rules = rules; // ----- plugins -const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); - -const definePlugin = new webpack.DefinePlugin({ - 'process.env': { - NODE_ENV: JSON.stringify('production') - } -}); - // webpack 4 enable optimization concatenateModules by default // https://medium.com/webpack/webpack-4-mode-and-optimization-5423a6bc597a // const moduleConcatPlugin = new webpack.optimize.ModuleConcatenationPlugin(); @@ -180,8 +172,6 @@ const bundleAnalyzerPlugin = new BundleAnalyzerPlugin({ // prints more readable module names in the browser console on HMR updates -module.exports.definePlugin = definePlugin; - let plugins = []; let pluginsCommon = []; if (isDev) { @@ -191,22 +181,6 @@ if (isDev) { plugins = [ ...pluginsCommon, new webpack.HashedModuleIdsPlugin(), - definePlugin, - // see https://github.com/webpack-contrib/uglifyjs-webpack-plugin - new UglifyJSPlugin({ - // enable parallelization. - // default number of concurrent runs: os.cpus().length - 1. - parallel: true, - // enable file caching. - // default path to cache directory: - // node_modules/.cache/uglifyjs-webpack-plugin. - cache: true - // debug - // uglifyOptions: { - // compress: false, - // mangle: false - // } - }), cssExtractPlugin, bundleAnalyzerPlugin ]; diff --git a/webpack.config.js b/webpack.config.js index f188dfd..3f97ceb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,6 +3,7 @@ const path = require('path'); const webpack = require('webpack'); const { rules, plugins } = require('./webpack.common'); +const TerserPlugin = require('terser-webpack-plugin'); const isDev = process.env.NODE_ENV !== 'production'; const resolveDir = dir => path.resolve(__dirname, dir); @@ -116,7 +117,16 @@ module.exports = { } } }, - runtimeChunk: true + runtimeChunk: true, + minimizer: [ + // the current uglifyjs-webpack-plugin has problems workin with React Hooks + // see also: + // https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/374 + new TerserPlugin({ + cache: true, + parallel: true + }) + ] }, plugins }; diff --git a/yarn.lock b/yarn.lock index 8642820..a307ecd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1613,7 +1613,7 @@ cacache@^10.0.4: unique-filename "^1.1.0" y18n "^4.0.0" -cacache@^11.2.0: +cacache@^11.0.2: version "11.2.0" resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.2.0.tgz#617bdc0b02844af56310e411c0878941d5739965" integrity sha512-IFWl6lfK6wSeYCHUXh+N1lY72UDrpyrYQJNIVQf48paDuWbv5RbAtJYf/4gUQFObTCHZwdZ5sI8Iw7nqwP6nlQ== @@ -7400,6 +7400,14 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" +source-map-support@~0.5.6: + version "0.5.9" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.9.tgz#41bc953b2534267ea2d605bccfa7bfa3111ced5f" + integrity sha512-gR6Rw4MvUlYy83vP0vxoVNzM6t8MUXqNuRsuBmBHQDu1Fh6X015FrLdgoDKcNdkwGubozq0P4N0Q37UyFVr1EA== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + source-map-url@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" @@ -7417,7 +7425,7 @@ source-map@^0.4.2: dependencies: amdefine ">=0.0.4" -source-map@^0.6.1, source-map@~0.6.1: +source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== @@ -7818,6 +7826,29 @@ tar@^4: safe-buffer "^5.1.2" yallist "^3.0.2" +terser-webpack-plugin@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.1.0.tgz#cf7c25a1eee25bf121f4a587bb9e004e3f80e528" + integrity sha512-61lV0DSxMAZ8AyZG7/A4a3UPlrbOBo8NIQ4tJzLPAdGOQ+yoNC7l5ijEow27lBAL2humer01KLS6bGIMYQxKoA== + dependencies: + cacache "^11.0.2" + find-cache-dir "^2.0.0" + schema-utils "^1.0.0" + serialize-javascript "^1.4.0" + source-map "^0.6.1" + terser "^3.8.1" + webpack-sources "^1.1.0" + worker-farm "^1.5.2" + +terser@^3.8.1: + version "3.10.4" + resolved "https://registry.yarnpkg.com/terser/-/terser-3.10.4.tgz#63ed0b5266d39cbdcb9c2bf6506f6444b70184a3" + integrity sha512-Gobjr6j9ZbA0oAFW+foiqp8LUZjBkd5UHxCVL0cPOlHO7wKKa3FwHW/j9p7d1/ypPl6m9Bf0LAFbbHf3k97asA== + dependencies: + commander "~2.17.1" + source-map "~0.6.1" + source-map-support "~0.5.6" + text-table@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" @@ -7993,14 +8024,6 @@ uglify-js@3.3.x: commander "~2.14.1" source-map "~0.6.1" -uglify-js@^3.0.0: - version "3.4.9" - resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3" - integrity sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q== - dependencies: - commander "~2.17.1" - source-map "~0.6.1" - uglifyjs-webpack-plugin@^1.2.4: version "1.3.0" resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.3.0.tgz#75f548160858163a08643e086d5fefe18a5d67de" @@ -8015,20 +8038,6 @@ uglifyjs-webpack-plugin@^1.2.4: webpack-sources "^1.1.0" worker-farm "^1.5.2" -uglifyjs-webpack-plugin@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-2.0.1.tgz#f346af53ed496ce72fef462517d417f62bec3010" - integrity sha512-1HhCHkOB6wRCcv7htcz1QRPVbWPEY074RP9vzt/X0LF4xXm9l4YGd0qja7z88abDixQlnVwBjXsTBs+Xsn/eeQ== - dependencies: - cacache "^11.2.0" - find-cache-dir "^2.0.0" - schema-utils "^1.0.0" - serialize-javascript "^1.4.0" - source-map "^0.6.1" - uglify-js "^3.0.0" - webpack-sources "^1.1.0" - worker-farm "^1.5.2" - unicode-canonical-property-names-ecmascript@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"