babel-plugin-optimize-i18n

0.1.0 • Public • Published

babel-plugin-optimize-i18n

A babel plugin for optimizing i18n locales file which can reduce 40% ~ 50% bundle size.

npm npm download

Install

npm i --save-dev babel-plugin-optimize-i18n

Usage

Add it into .babelrc.

{
  "plugins": [
    "optimize-i18n"
  ]
}

Result

The source i18n text file below:

{
  "module.left.title": "左侧标题",
  "module.right.title": "右侧标题"
}

will be transformed to:

{
  $1: "左侧标题",
  $2: "右侧标题"
}

Configure

You can customize the configure of the plugin.

{
  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.

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.

Package Sidebar

Install

npm i babel-plugin-optimize-i18n

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

7.11 kB

Total Files

8

Last publish

Collaborators

  • atool