Skip to content

Commit

Permalink
perf(stark-build): remove deprecated Angular PurifyPlugin. Enhance Ug…
Browse files Browse the repository at this point in the history
…lifyJs options to improve performance.

ISSUES CLOSED: #623
  • Loading branch information
christophercr committed Oct 30, 2018
1 parent 290934c commit ff621c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 0 additions & 3 deletions packages/stark-build/config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -356,8 +355,6 @@ module.exports = options => {
*/
new AngularNamedLazyChunksWebpackPlugin(),

new PurifyPlugin(),

new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /node_modules/,
Expand Down
22 changes: 12 additions & 10 deletions packages/stark-build/config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -334,9 +340,5 @@ module.exports = function() {
]
});

if (!isCITestEnv) {
webpackConfig.devtool = "source-map";
}

return webpackConfig;
};

0 comments on commit ff621c5

Please sign in to comment.