From 90e0fd35ff50706d0bf501095ba6529809308370 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 4 Apr 2024 17:17:21 -0400 Subject: [PATCH] feat: add WebPack TerserPlugin for mangling --- package-lock.json | 1 + package.json | 3 ++- webpack.config.js | 40 ++++++++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 82c36711..b0b3b616 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "sass": "^1.70.0", "sass-loader": "^14.1.0", "style-loader": "^3.3.4", + "terser-webpack-plugin": "^5.3.10", "ts-jest": "^29.1.2", "ts-loader": "^9.5.1", "typescript": "^5.3.3", diff --git a/package.json b/package.json index e2d55ef0..884960f5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/webpack.config.js b/webpack.config.js index bd7e0182..0b7a7a5a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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'; @@ -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'; }