Skip to content

nettleweb/string-pool-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Pool Plugin

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.

Example Usage

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;

Install

npm install string-pool-plugin@latest

License

This repository is licensed under the MIT License. You are free to modify or redistribute this project under the terms stated in LICENSE.md.

About

A simple string pool deduplicate plugin for webpack.

Resources

License

Stars

Watchers

Forks