Skip to content

Commit

Permalink
feat: add WebPack TerserPlugin for mangling
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraviolet-jordan committed Apr 4, 2024
1 parent 05c4e24 commit 90e0fd3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"webpack": "^5.90.0",
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
"webpack-dev-server": "^4.15.1",
"terser-webpack-plugin": "^5.3.10"
},
"scripts": {
"build": "npm run asc && webpack --mode=production --node-env=production",
Expand Down
40 changes: 34 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
// const TerserPlugin = require('terser-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

const isProduction = process.env.NODE_ENV === 'production';
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : 'style-loader';
Expand Down Expand Up @@ -115,20 +115,48 @@ module.exports = () => {
if (isProduction) {
config.mode = 'production';
config.plugins.push(new MiniCssExtractPlugin());
/*config.plugins.push(
config.plugins.push(
new TerserPlugin({
exclude: /\/tinymidipcm/,
minify: TerserPlugin.terserMinify,
parallel: true,
terserOptions: {
mangle: {
properties: true
properties: {
keep_quoted: true, // needed for tinymidipcm.mjs
reserved: [
'loadTinyMidiPCM', // needed for tinymidipcm.mjs
'newBzip2State', // keeps renaming this to $S
'portOffset', // idk why but has to
'willReadFrequently', // terser removes this option from canvas
'__liftRecord5', // the rest is for vendor
'__lowerRecord5',
'__liftString',
'__liftArray',
'__lowerArray',
'__liftTypedArray',
'__lowerTypedArray',
'__liftStaticArray',
'__lowerStaticArray',
'__retain',
'__release',
'__notnull',
'__setU8',
'__setU32',
'__getU8',
'__getU32',
'__pin',
'__new',
'__unpin'
]
}
},
format: {
quote_style: 3 // original
quote_style: 3, // original
keep_quoted_props: true // needed for tinymidipcm.mjs
}
}
})
);*/
);
} else {
config.mode = 'development';
}
Expand Down

0 comments on commit 90e0fd3

Please sign in to comment.