A simple string pool deduplicate plugin for webpack. It rewrites the script after bundling to replace all the inline string literals and keep them in a string pool. This helps to reduce the bundle size by keeping duplicated strings as variables after minifying.
Note: This plugin should be combined with another minifier, otherwise you may experience a significant increase in bundle file size.
webpack.config.js
:
import TerserPlugin from "terser-webpack-plugin";
import StringPoolPlugin from "string-pool-plugin";
/**
* @type {import("webpack").Configuration}
*/
const config = {
mode: "production",
entry: "./main.ts", // replace with your own entry file
cache: true,
output: {
// specify the output file here
},
performance: { hints: false },
optimization: {
minimize: true,
minimizer: [
new TerserPlugin(), // It is important to combine with another minifier, otherwise bundle might become larger
new StringPoolPlugin() // apply the string pool plugin
],
// other optimization flags can be added
}
};
export default config;
npm install string-pool-plugin@latest
This repository is licensed under the MIT License. You are free to modify or redistribute this project under the terms stated in LICENSE.md
.