Skip to content

Commit ddf2d6e

Browse files
author
Ahmad Awais
committed
👌 IMPROVE: UglifyJsPlugin For Webpack
1 parent b2fdf43 commit ddf2d6e

4 files changed

Lines changed: 562 additions & 11 deletions

File tree

‎packages/cgb-scripts/config/webpack.config.dev.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
* @since 1.0.0
2121
*/
2222

23-
// const path = require( 'path' );
23+
const paths = require( './paths' );
2424
const autoprefixer = require( 'autoprefixer' );
2525
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
26-
const paths = require( './paths' );
2726

2827
// Extract style.css for both editor and frontend styles.
2928
const blocksCSSPlugin = new ExtractTextPlugin( {
@@ -72,13 +71,11 @@ const extractConfig = {
7271
// Export configuration.
7372
module.exports = {
7473
entry: {
75-
// './dist/blocks.build': './src/blocks.js', // 'name' : 'path/file.ext'.
7674
'./dist/blocks.build': paths.pluginBlocksJs, // 'name' : 'path/file.ext'.
7775
},
7876
output: {
7977
// Add /* filename */ comments to generated require()s in the output.
8078
pathinfo: true,
81-
// path: path.resolve( __dirname ),
8279
// The dist folder.
8380
path: paths.pluginDist,
8481
filename: '[name].js', // [name] = './dist/blocks.build' as defined above.

‎packages/cgb-scripts/config/webpack.config.prod.js‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
* @since 1.0.0
2121
*/
2222

23-
// const path = require( 'path' );
23+
const paths = require( './paths' );
24+
const webpack = require( 'webpack' );
2425
const autoprefixer = require( 'autoprefixer' );
2526
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
26-
const paths = require( './paths' );
27+
28+
// Source maps are resource heavy and can cause out of memory issue for large source files.
29+
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
2730

2831
// Extract style.css for both editor and frontend styles.
2932
const blocksCSSPlugin = new ExtractTextPlugin( {
@@ -72,13 +75,11 @@ const extractConfig = {
7275
// Export configuration.
7376
module.exports = {
7477
entry: {
75-
// './dist/blocks.build': './src/blocks.js', // 'name' : 'path/file.ext'.
7678
'./dist/blocks.build': paths.pluginBlocksJs, // 'name' : 'path/file.ext'.
7779
},
7880
output: {
7981
// Add /* filename */ comments to generated require()s in the output.
8082
pathinfo: true,
81-
// path: path.resolve( __dirname ),
8283
// The dist folder.
8384
path: paths.pluginDist,
8485
filename: '[name].js', // [name] = './dist/blocks.build' as defined above.
@@ -117,7 +118,31 @@ module.exports = {
117118
],
118119
},
119120
// Add plugins.
120-
plugins: [ blocksCSSPlugin, editBlocksCSSPlugin ],
121+
plugins: [
122+
blocksCSSPlugin,
123+
editBlocksCSSPlugin,
124+
// Minify the code.
125+
new webpack.optimize.UglifyJsPlugin( {
126+
compress: {
127+
warnings: false,
128+
// Disabled because of an issue with Uglify breaking seemingly valid code:
129+
// https://github.com/facebookincubator/create-react-app/issues/2376
130+
// Pending further investigation:
131+
// https://github.com/mishoo/UglifyJS2/issues/2011
132+
comparisons: false,
133+
},
134+
mangle: {
135+
safari10: true,
136+
},
137+
output: {
138+
comments: false,
139+
// Turned on because emoji and regex is not minified properly using default
140+
// https://github.com/facebookincubator/create-react-app/issues/2488
141+
ascii_only: true,
142+
},
143+
sourceMap: shouldUseSourceMap,
144+
} ),
145+
],
121146
stats: 'minimal',
122147
// stats: 'errors-only',
123148
};

0 commit comments

Comments
 (0)