Skip to content

Commit

Permalink
Improve production build speed (PatrickJS#2004)
Browse files Browse the repository at this point in the history
* Update readme to reflect the latest updates of project

* Replace inactive `inline-manifest-webpack-plugin` with the maintained fork `webpack-inline-manifest-plugin`, version 4.0.0 is for webpack 3, version 4.0.1+ for webpack 4+

* Minor updates for package dependencies

* Minor updates for package dependencies

* Disable sourceMap by default for prod build and provide EVN option to enable it

* minor change by providing uglify cache to improve build process for prod

* Because of npm 5 and yarn, no need to force cache clean, verify should be enough

* Update dependencies
  • Loading branch information
almothafar authored and PatrickJS committed Apr 19, 2018
1 parent f833873 commit 8936c61
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 322 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ npm-debug.log
.webpack.json
/compiled/
dll/
temp
tmp
webpack-cache

# Doc #
/doc/
Expand Down
22 changes: 14 additions & 8 deletions config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ const PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
const ModuleConcatenationPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');



function getUglifyOptions (supportES2015) {
/***
* Ref: https://github.com/mishoo/UglifyJS2/tree/harmony#minify-options
* @param supportES2015
* @param enableCompress disabling compress could improve the performance, see https://github.com/webpack/webpack/issues/4558#issuecomment-352255789
* @returns {{ecma: number, warnings: boolean, ie8: boolean, mangle: boolean, compress: {pure_getters: boolean, passes: number}, output: {ascii_only: boolean, comments: boolean}}}
*/
function getUglifyOptions(supportES2015, enableCompress) {
const uglifyCompressOptions = {
pure_getters: true, /* buildOptimizer */
// PURE comments work best with 3 passes.
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
passes: 3 /* buildOptimizer */
passes: 2 /* buildOptimizer */
};

return {
ecma: supportES2015 ? 6 : 5,
warnings: false, // TODO verbose based on option?
ie8: false,
mangle: true,
compress: uglifyCompressOptions,
compress: enableCompress ? uglifyCompressOptions : false,
output: {
ascii_only: true,
comments: false
Expand All @@ -49,6 +53,7 @@ function getUglifyOptions (supportES2015) {
module.exports = function (env) {
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
const supportES2015 = buildUtils.supportES2015(buildUtils.DEFAULT_METADATA.tsConfigPath);
const sourceMapEnabled = process.env.SOURCE_MAP === '1';
const METADATA = Object.assign({}, buildUtils.DEFAULT_METADATA, {
host: process.env.HOST || 'localhost',
port: process.env.PORT || 8080,
Expand All @@ -59,7 +64,7 @@ module.exports = function (env) {
// set environment suffix so these environments are loaded.
METADATA.envFileSuffix = METADATA.E2E ? 'e2e.prod' : 'prod';

return webpackMerge(commonConfig({ env: ENV, metadata: METADATA }), {
return webpackMerge(commonConfig({env: ENV, metadata: METADATA}), {

/**
* Options affecting the output of the compilation.
Expand Down Expand Up @@ -171,9 +176,10 @@ module.exports = function (env) {
* NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
*/
new UglifyJsPlugin({
sourceMap: true,
sourceMap: sourceMapEnabled,
parallel: true,
uglifyOptions: getUglifyOptions(supportES2015)
cache: helpers.root('webpack-cache/uglify-cache'),
uglifyOptions: getUglifyOptions(supportES2015, true)
}),

/**
Expand Down
Loading

0 comments on commit 8936c61

Please sign in to comment.