Skip to content

Commit

Permalink
Use Webpack's Terser plugin instead of Uglify
Browse files Browse the repository at this point in the history
  • Loading branch information
arelra committed Apr 27, 2023
1 parent 7c46229 commit c726263
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 63 deletions.
46 changes: 25 additions & 21 deletions webpack.config.atoms.js
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,
},
}),
],
},
});
90 changes: 48 additions & 42 deletions webpack.config.prod.js
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,
},
}),
],
},
});

0 comments on commit c726263

Please sign in to comment.