Skip to content

Commit

Permalink
Initial released version
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmadsen committed Jan 14, 2019
1 parent 02c7b4e commit a94f800
Show file tree
Hide file tree
Showing 10 changed files with 7,470 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# parcel-plugin-localization-bundler
# 📦🚀 parcel-plugin-localization-bundler

A plugin that bundles localization files into one bundle per namespace and language

The structur must be `${language}/${namespace}/localeFile.json`

Eg. the following locale structur

```
/en/pages.json
/en/pages/1.json
/en/pages/2.json
/en/pages/3.json
/en/plugins.json
/en/plugins/1.json
/en/plugins/2.json
/en/plugins/3.json
/de/pages.json
/de/pages/1.json
/de/pages/2.json
/de/pages/3.json
/de/plugins.json
/de/plugins/1.json
/de/plugins/2.json
/de/plugins/3.json
```
Would result in 4 bundles, one for each namespace; `pages` and `plugins`, and one for each language of the given namespace, `en` and `de`.

# Setup

```
npm i parcel-plugin-localization-bundler
```

There must be a `parcel-plugin-localization-bundler` section in your `package.json`, containing:
```json
...
"parcel-plugin-localization-bundler": {
"entryFile": "index.tsx",
"sourcePath": "localizations"
}
...
```
The entryFile determines which file in your project that the new bundles should be dynamic dependencies of.
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const getConfig = require("./src/helpers/getConfig")
const logger = require('@parcel/logger')

module.exports = async bundler => {
const config = await getConfig(bundler.options.rootDir)
if (config) {
bundler.addAssetType('js', require.resolve('./src/JSAsset'))
bundler.addAssetType('json', require.resolve('./src/JSONAsset'))
} else {
logger.error(`[parcel-plugin-localization-bundler]: Missing configuration in package.json`)
}
}

0 comments on commit a94f800

Please sign in to comment.