0.0.4 • Published 6 years ago

lang-loader v0.0.4

Weekly downloads
36
License
MIT
Repository
github
Last release
6 years ago

Language Loader

This is a webpack loader which can help to load and parse lang.json file. So that you don't have to pack all your language files. It is used to help reduce the compiled JS size if you use i18n.

Install

npm i --save-dev lang-loader

Usage

Build your lang.json

{
  "en": {
    "test": "TEST"
  },
  "zh-CN": {
    "test": "测试"
  }
}

webpack.config.js

module.exports = {
  module: {
    rules: [{
        loader: 'lang-loader',
        test: /lang.json$/,
        query: {
          language: language
        }
    }]
  }
}

Use it in your file

const __ = require('./lang.json');

If your language is set to 'en', the __ will look like this:

{
  "test": "TEST"
}

Benifit

The benifit of this loader is that you don't have to put all your i18n content in a single JS. You can generate your JS file for each language like: en.content.min.js zh-CN.content.min.js Then your JS file's size can be reduced.

Have fun!

0.0.4

6 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago