-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Webpack's Terser plugin instead of Uglify
- Loading branch information
Showing
2 changed files
with
73 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
const path = require('path'); | ||
const webpackMerge = require('webpack-merge'); | ||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
|
||
const config = require('./webpack.config.js'); | ||
|
||
// Blatantly override JS entry points | ||
config.entry = { | ||
snippet: path.join( | ||
__dirname, | ||
'static', | ||
'src', | ||
'javascripts', | ||
'bootstraps', | ||
'atoms', | ||
'snippet.js' | ||
), | ||
snippet: path.join( | ||
__dirname, | ||
'static', | ||
'src', | ||
'javascripts', | ||
'bootstraps', | ||
'atoms', | ||
'snippet.js', | ||
), | ||
}; | ||
|
||
module.exports = webpackMerge.smart(config, { | ||
devtool: 'source-map', | ||
output: { | ||
filename: `[chunkhash]/graun.[name].js`, | ||
chunkFilename: `[chunkhash]/graun.[name].js`, | ||
}, | ||
plugins: [ | ||
new UglifyJSPlugin({ | ||
parallel: true, | ||
sourceMap: true, | ||
}), | ||
], | ||
devtool: 'source-map', | ||
output: { | ||
filename: `[chunkhash]/graun.[name].js`, | ||
chunkFilename: `[chunkhash]/graun.[name].js`, | ||
}, | ||
optimization: { | ||
minimizer: [ | ||
new TerserPlugin({ | ||
parallel: true, | ||
terserOptions: { | ||
sourceMap: true, | ||
}, | ||
}), | ||
], | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
const webpack = require('webpack'); | ||
const webpackMerge = require('webpack-merge'); | ||
const Visualizer = require('webpack-visualizer-plugin2'); | ||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') | ||
.BundleAnalyzerPlugin; | ||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); | ||
const CopyPlugin = require("copy-webpack-plugin"); | ||
const BundleAnalyzerPlugin = | ||
require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
const CopyPlugin = require('copy-webpack-plugin'); | ||
|
||
const config = require('./webpack.config.js'); | ||
|
||
module.exports = webpackMerge.smart(config, { | ||
mode: 'production', | ||
output: { | ||
filename: `[chunkhash]/graun.[name].js`, | ||
chunkFilename: `[chunkhash]/graun.[name].js`, | ||
}, | ||
devtool: 'source-map', | ||
plugins: [ | ||
// Copy the commercial bundle dist to Frontend's static output location: | ||
// static/target/javascripts/commercial | ||
new CopyPlugin({ | ||
patterns: [ | ||
{ | ||
from: "node_modules/@guardian/commercial-bundle/dist", | ||
to: "commercial" | ||
}, | ||
], | ||
}), | ||
new webpack.optimize.AggressiveMergingPlugin({ | ||
// delicate number: stops enhanced-no-commercial and enhanced | ||
// being merged into one | ||
minSizeReduce: 1.6, | ||
}), | ||
new Visualizer({ | ||
filename: './webpack-stats.html', | ||
}), | ||
new BundleAnalyzerPlugin({ | ||
reportFilename: './bundle-analyzer-report.html', | ||
analyzerMode: 'static', | ||
openAnalyzer: false, | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}), | ||
new UglifyJSPlugin({ | ||
parallel: true, | ||
sourceMap: true, | ||
}), | ||
], | ||
mode: 'production', | ||
output: { | ||
filename: `[chunkhash]/graun.[name].js`, | ||
chunkFilename: `[chunkhash]/graun.[name].js`, | ||
}, | ||
devtool: 'source-map', | ||
plugins: [ | ||
// Copy the commercial bundle dist to Frontend's static output location: | ||
// static/target/javascripts/commercial | ||
new CopyPlugin({ | ||
patterns: [ | ||
{ | ||
from: 'node_modules/@guardian/commercial-bundle/dist', | ||
to: 'commercial', | ||
}, | ||
], | ||
}), | ||
new webpack.optimize.AggressiveMergingPlugin({ | ||
// delicate number: stops enhanced-no-commercial and enhanced | ||
// being merged into one | ||
minSizeReduce: 1.6, | ||
}), | ||
new Visualizer({ | ||
filename: './webpack-stats.html', | ||
}), | ||
new BundleAnalyzerPlugin({ | ||
reportFilename: './bundle-analyzer-report.html', | ||
analyzerMode: 'static', | ||
openAnalyzer: false, | ||
}), | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}), | ||
], | ||
optimization: { | ||
minimizer: [ | ||
new TerserPlugin({ | ||
parallel: true, | ||
terserOptions: { | ||
sourceMap: true, | ||
}, | ||
}), | ||
], | ||
}, | ||
}); |