https://github.com/hustcc/babel-plugin-optimize-i18n
:key: 优化国际化文案的 Babel 插件,可以减少国际化文案 40% ~ 50% 的 bundle size。
https://github.com/hustcc/babel-plugin-optimize-i18n
babel-plugin i18n optimize-i18n
Last synced: about 1 year ago
JSON representation
:key: 优化国际化文案的 Babel 插件,可以减少国际化文案 40% ~ 50% 的 bundle size。
- Host: GitHub
- URL: https://github.com/hustcc/babel-plugin-optimize-i18n
- Owner: hustcc
- Created: 2018-10-18T07:29:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-01T08:32:49.000Z (over 7 years ago)
- Last Synced: 2025-02-28T19:12:02.495Z (over 1 year ago)
- Topics: babel-plugin, i18n, optimize-i18n
- Language: JavaScript
- Homepage: https://github.com/hustcc/babel-plugin-optimize-i18n
- Size: 9.77 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-babel - optimize-i18n - Optimizing i18n bundle file by shorten the locale key. (Plugins / Optimization)
README
# babel-plugin-optimize-i18n
A babel plugin for optimizing i18n locales file which can reduce 40% ~ 50% bundle size.
[](https://www.npmjs.com/package/babel-plugin-optimize-i18n)
[](https://www.npmjs.com/package/babel-plugin-optimize-i18n)
## Install
> npm i --save-dev babel-plugin-optimize-i18n
## Usage
Add it into `.babelrc`.
```json
{
"plugins": [
"optimize-i18n"
]
}
```
## Result
The source i18n text file below:
```json
{
"module.left.title": "左侧标题",
"module.right.title": "右侧标题"
}
```
will be transformed to:
```js
{
$1: "左侧标题",
$2: "右侧标题"
}
```
## Configure
You can customize the configure of the plugin.
```js
{
localeFiles: ['zh_CN', 'en_US'],
i18nFunction: {
object: 'intl',
property: 'get'
},
uniquePrefix: '$',
}
```
## Test
```
npm i
npm t
```
Then see the files in `lib` dir.
## Constraint
For example, when you use the function below to format i18n text.
```js
intl.get('key', params);
```
You should be sure the 1st parameter of `intl.get` is string constant, or will be build error.
## License
MIT@[hustcc](https://github.com/hustcc).