Using Webpack 2.3.3 and Babel-loader
I'm new to using Webpack and am trying to bundle angular-i18n locale files using webpack. I have a config object which lists out the app's supported locales. For example:
var supportedLocales = {
'FR': {
currency: 'EUR',
id: 'fr-fr'
},
'GB': {
currency: 'GBP',
id: 'en-gb',
},
'US': {
currency: 'USD',
id: 'en-us'
}
}
When I install angular-i18n library, it outputs ALL the locales in node_modules/angular-i18n/
directory. For example:
node_modules/
|_ angular-i18n/
|_ angular-locale_en-gb.js
|_ angular-locale_en-us.js
|_ angular-locale_fr-fr.js
|_ ...
webpack.config.js (simplified for post)
module.exports = {
context: path.join(config.appDir, '/client/assets'),
entry: {
main: [
'./js/index.js'
]
},
plugins: [
new webpack.DefinePlugin({
'SUPPORTED_LOCALES': JSON.stringify({
supportedLocales
})
}),
module: {..etc}
};
- Is there a way to dynamically load just these specific angular-locale files based on the
supportedLocales
and include it in themain.js
bundle? For example:
index.js
// This doesn't work
_.each(SUPPORTED_LOCALES, function(locale) {
require(`angular-i18n/angular-locale_${locale.id}`);
})
- Would it be possible to bundle just these specific angular-locale files and include it as a new file
locales.js
on app runtime?
Any help would be much appreciated.