I am attempting to dynamically import i18n
files using webpack
:
function getI18n(lang) {
return import(/* webpackChunkName "i18n/[request]" */ `./locales/${lang}.json`)
.then(/*whatever*/)
}
However, I have noticed that all the files from the specified folder are being loaded even before the function is called:
- i18n/en.json.js
- i18n/ru.json.js
- i18n/nl.json.js
- i18n/nw.json.js
This is not the behavior I desire. I want to lazily load the required chunk dynamically during runtime.
An interesting observation is, if I rename the files ru
to ru2
and nw
to nw2
and adjust the import path accordingly, like this: ./locales/${lang}2.json
, only the files i18n/ru2.json.js
and i18n/nw2.json.js
are loaded while the others without the character 2
in their name are ignored. It appears to operate based on a regular expression rather than an exact match.
Thank you
P.S. I am using vuejs
and typescript
, so the issue might be related to those technologies. I have been trying to follow this example vuei18n lazy load with my own code.