Hello everyone!
A bit of story: I am working on multilingual project and now I am integrating momentjs into my project.
As you probably know - momentjs has a lot of i18n files for different languages. All i18n code is stored in js files.
Basically if you don’t need to support lots of languages - you just import necessary language.
But if you wish to handle all possible languages - you need to dynamically import them.
This task was very easy achievable on my previous projects with requirejs - you just type require(['some/path/to/locales' + locale], cb, errCb)
and bam, its ready to use.
My configuration is webpack + babel.
I have tried to use ES6 import()
to achieve the same.
Here I sucked with aurelia webpack plugin.
So, what have I done:
First of all I need to copy all i18n files, webpack.config.js
:
new CopyWebpackPlugin([
{ from: 'src/locales/', to: 'locales/' },
{ from: 'node_modules/moment/locale', to: 'locales/modules/moment'}
]),
Then, we installing babel plugin to handle import()
- yarn add babel-plugin-syntax-dynamic-import -D
And connect it in .babelrc.js
:
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"syntax-dynamic-import"
],
Lets do, some import: import('/locales/modules/moment/en');
and compile it. Keep in mind - there is can be anything instead of en
and this is impossible to know before application startup.
And… it just does not work
ERROR in ./src/main.js
Module not found: Error: Can't resolve '/locales/modules/moment/en' in 'D:\Work\TRIMS-app\src'
@ ./src/main.js 198:2-38
@ ./node_modules/aurelia-webpack-plugin/runtime/empty-entry.js
@ multi aurelia-webpack-plugin/runtime/empty-entry aurelia-webpack-plugin/runtime/pal-loader-entry aurelia-bootstrapper
Also, I tried a require method with the same results.
Is there any way to “tell” aurelia webpack plugin to ignore some specific modules?
Or maybe I am something missing?
I will be grateful for any help or suggestions.
Thanks in advance.