Registry / serialization / webpack-localize-assets-plugin

webpack-localize-assets-plugin

JSON →
library1.5.4jsnpmunverified

Webpack plugin that localizes bundle output by replacing `__()` calls with locale-specific strings, generating separate files per locale. Current stable version is 1.5.4, released January 2023. Supports Webpack 4 and 5, with TypeScript type definitions included. Key differentiators: supports single and multiple locales, blazing fast, and offers features like source map per locale, warning on unused strings, and a custom localize compiler for advanced replacement logic. Compared to i18n-webpack-plugin, it's more flexible and actively maintained.

npm install webpack-localize-assets-plugin
INSTALL
IMPORT
SIG · WEBPACK-LOCALIZE-A
W
webpack-localize-assets-plugin
serializationjavascriptv1.5.4
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LocalizeAssetsPlugin
✓ import LocalizeAssetsPlugin from 'webpack-localize-assets-plugin'
✗ const { LocalizeAssetsPlugin } = require('webpack-localize-assets-plugin')
This is a default export. In CommonJS, use require('webpack-localize-assets-plugin').default or const LocalizeAssetsPlugin = require('webpack-localize-assets-plugin').

Webpack configuration to generate locale-specific bundles using the localize plugin.

const LocalizeAssetsPlugin = require('webpack-localize-assets-plugin'); const path = require('path'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: '[name].[locale].js', }, plugins: [ new LocalizeAssetsPlugin({ locales: { en: { greeting: 'Hello' }, es: { greeting: 'Hola' }, }, functionName: '__', }), ], };
Debug
Known issues
gotchaWhen using output.filename, you must include `[locale]` placeholder. If omitted, only the last locale will overwrite previous outputs.
fix
Use `[locale]` in filename, e.g., `filename: '[name].[locale].js'`.
affects: >=1.0.0
deprecatedIn version 1.5.0, using filenames without `[locale]` in single locale mode is allowed, but in multi-locale mode it may cause overwriting.
fix
Always include `[locale]` for multi-locale builds.
affects: >=1.5.0
breakingWebpack 4 compatibility: The plugin uses `Chunk.getModules` which is deprecated in Webpack 5. Fixed in v1.4.2.
fix
Upgrade to v1.4.2 or later.
affects: <1.4.2
gotchaContent hash (e.g., `[contenthash]`) is not automatically unique across locales. Fixed in v1.3.0 to use `realContentHash`.
fix
Upgrade to v1.3.0 or later; ensure `output.hashSalt` is not set.
affects: <1.3.0
gotchaIf locale values contain double quotes, devtool eval may break. Fixed in v1.5.1 and v1.5.2.
fix
Upgrade to v1.5.2 or later.
affects: <1.5.1
gotchaUnused locale strings are not automatically minified. Enable `warnOnUnusedString` to detect them.
fix
Set `warnOnUnusedString: true` in plugin options.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'locales' of 'undefined' or 'null'
Plugin instantiated without options or `locales` option is missing.
fix
Ensure to pass an object with `locales` property: `new LocalizeAssetsPlugin({ locales: {...} })`
Error: Locale 'en' is not found in locale data
Locale key in `locales` does not match the key used in the build configuration or a missing locale.
fix
Check that all locale keys in `locales` match the expected locale names. For single locale mode, ensure the locale key is present in options.
WARNING: Unused string key 'xyz' found in locale 'en'
String key defined in locale but never used via `__()` function.
fix
Either remove the unused key from locale data or use it in code to avoid warning.
Error: contenthash is not unique across locales
Output filename doesn't include `[locale]` or content hash collision.
fix
Add `[locale]` to output.filename and ensure `output.realContentHash` is true (Webpack 5).
Upgrade
Version history
1.5.4latest on npm
Audit
Dependencies
webpackrequiredPeer dependency required for plugin functionality
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
webpack-localize-assets-plugin — npm install webpack-localize-assets-plugin · libregistry