|
20 | 20 | * @since 1.0.0 |
21 | 21 | */ |
22 | 22 |
|
23 | | -// const path = require( 'path' ); |
| 23 | +const paths = require( './paths' ); |
| 24 | +const webpack = require( 'webpack' ); |
24 | 25 | const autoprefixer = require( 'autoprefixer' ); |
25 | 26 | 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'; |
27 | 30 |
|
28 | 31 | // Extract style.css for both editor and frontend styles. |
29 | 32 | const blocksCSSPlugin = new ExtractTextPlugin( { |
@@ -72,13 +75,11 @@ const extractConfig = { |
72 | 75 | // Export configuration. |
73 | 76 | module.exports = { |
74 | 77 | entry: { |
75 | | - // './dist/blocks.build': './src/blocks.js', // 'name' : 'path/file.ext'. |
76 | 78 | './dist/blocks.build': paths.pluginBlocksJs, // 'name' : 'path/file.ext'. |
77 | 79 | }, |
78 | 80 | output: { |
79 | 81 | // Add /* filename */ comments to generated require()s in the output. |
80 | 82 | pathinfo: true, |
81 | | - // path: path.resolve( __dirname ), |
82 | 83 | // The dist folder. |
83 | 84 | path: paths.pluginDist, |
84 | 85 | filename: '[name].js', // [name] = './dist/blocks.build' as defined above. |
@@ -117,7 +118,31 @@ module.exports = { |
117 | 118 | ], |
118 | 119 | }, |
119 | 120 | // 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 | + ], |
121 | 146 | stats: 'minimal', |
122 | 147 | // stats: 'errors-only', |
123 | 148 | }; |
0 commit comments