From ff621c59aeb52de7dec5c607229febb1038d1fb4 Mon Sep 17 00:00:00 2001 From: christophercr Date: Tue, 30 Oct 2018 12:56:53 +0100 Subject: [PATCH] perf(stark-build): remove deprecated Angular PurifyPlugin. Enhance UglifyJs options to improve performance. ISSUES CLOSED: #623 --- packages/stark-build/config/webpack.common.js | 3 --- packages/stark-build/config/webpack.prod.js | 22 ++++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/stark-build/config/webpack.common.js b/packages/stark-build/config/webpack.common.js index 4c1e6b5966..390335e371 100644 --- a/packages/stark-build/config/webpack.common.js +++ b/packages/stark-build/config/webpack.common.js @@ -21,7 +21,6 @@ const HtmlElementsWebpackPlugin = require("html-elements-webpack-plugin"); const AngularNamedLazyChunksWebpackPlugin = require("angular-named-lazy-chunks-webpack-plugin"); const ContextReplacementPlugin = require("webpack/lib/ContextReplacementPlugin"); const CircularDependencyPlugin = require("circular-dependency-plugin"); -const PurifyPlugin = require("@angular-devkit/build-optimizer").PurifyPlugin; const buildUtils = require("./build-utils"); @@ -356,8 +355,6 @@ module.exports = options => { */ new AngularNamedLazyChunksWebpackPlugin(), - new PurifyPlugin(), - new CircularDependencyPlugin({ // exclude detection of files based on a RegExp exclude: /node_modules/, diff --git a/packages/stark-build/config/webpack.prod.js b/packages/stark-build/config/webpack.prod.js index 5a2ace0e83..80e17021ec 100644 --- a/packages/stark-build/config/webpack.prod.js +++ b/packages/stark-build/config/webpack.prod.js @@ -17,13 +17,12 @@ const commonData = require("./webpack.common-data.js"); * Webpack Plugins */ const SourceMapDevToolPlugin = require("webpack/lib/SourceMapDevToolPlugin"); -const PurifyPlugin = require("@angular-devkit/build-optimizer").PurifyPlugin; const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); const HashedModuleIdsPlugin = require("webpack/lib/HashedModuleIdsPlugin"); -function getUglifyOptions(supportES2015, isCITestEnv = false) { +function getUglifyOptions(supportES2015, isCITestEnv) { const uglifyCompressOptions = { pure_getters: true /* buildOptimizer */, // PURE comments work best with 3 passes. @@ -72,6 +71,12 @@ module.exports = function() { mode: "production", + devtool: isCITestEnv ? undefined : "source-map", + + performance: { + hints: "warning" + }, + // reference: https://medium.com/webpack/webpack-4-mode-and-optimization-5423a6bc597a optimization: { removeAvailableModules: true, @@ -97,7 +102,11 @@ module.exports = function() { new UglifyJsPlugin({ parallel: true, // use multi-process parallel running to improve the build speed (default concurrent processes: os.cpus().length - 1) sourceMap: !isCITestEnv, // useful to still be able to debug in production - uglifyOptions: getUglifyOptions(supportES2015), + uglifyOptions: getUglifyOptions(supportES2015, isCITestEnv), + exclude: [ + /\/prettier\/parser-.*/, // prettier parsers are the biggest chunks and are already minified :p + /\/prettier\/standalone\.js/ // also one of the prettier's biggest chunks + ], cache: true }), // other options than Uglify: BabelifyMinifyWebpackPlugin or ClosureCompilerPlugin @@ -317,9 +326,6 @@ module.exports = function() { chunkFilename: "[id].[contenthash].css" }), - // TODO remove since it's probably useless here (defined in webpack.common.js) - new PurifyPlugin() /* buildOptimizer */, - /** * Plugin: HashedModuleIdsPlugin * Description: This plugin will cause hashes to be based on the relative path of the module, @@ -334,9 +340,5 @@ module.exports = function() { ] }); - if (!isCITestEnv) { - webpackConfig.devtool = "source-map"; - } - return webpackConfig; };