-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chunking/tree shaking via lang-based named imports #4
Comments
Named exports were added as part of #3. Need to try dynamic import as well as update docs if it works. |
I added this to the readme - one idea is to look into how vite supports tree shaking of json, and perhaps export as json itself instead of using named exports? https://vitejs.dev/guide/features.html#json Note that the virtual module generated has contents that conform to the i18next resource format. While using the output with NOTE as shown by the test output below, due to ES syntactical rules, we cannot use hyphenated lang codes. I'm open to ideas, but in the interim, affected lang codes are exported with the hyphen converted to underscore e.g. export const en = {
foo: { test: 'app foo.test en' },
main: {
test: 'app test en',
sub: {
slug: 'app sub.slug en',
test: 'lib sub.test en',
subsub: { slugslug: 'app sub.subsub.slugsub en', test: 'lib sub.subsub.test en' },
},
},
}
export const zh_cn = {
foo: { test: 'app foo.test zh-cn' },
main: {
test: 'app test zh-cn',
sub: {
slug: 'app sub.slug zh-cn',
test: 'lib sub.test zh-cn',
subsub: { slugslug: 'app sub.subsub.slugsub zh-cn', test: 'lib sub.subsub.test zh-cn' },
},
},
}
const resources = {
en,
'zh-cn': zh_cn,
}
export default resources |
@rosskevin I don't think tree shaking will work because of this issue rollup/rollup#2512 in rollup |
@rosskevin any moment on this? |
@veeramarni I have no pressing need, but I'm open to PRs. |
Since the output of the plugin is an ESM export, perhaps it makes sense for us to enumerate langs and export them independently at the top, in addition to one default export (which includes all langs for those that don't care).
I suspect that a named dynamic import would then be tree-shakeable. I could be wrong, but interested in other's thoughts.
The text was updated successfully, but these errors were encountered: