You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use moment.js for date formatting. Unfortunately they have a dynamic require in their code for language files - so webpack includes all of them.
Shouldn’t webpack just create a chunk for each dynamically loadable language? The script already supports dynamic loading, probably to solve the exact problem webpack’s mishandling of it causes (it solves the problem of throwing irrelevant JavaScript that the browser will never call at the browser).
Activity
sokra commentedon May 13, 2013
ContextReplacementPlugin
It's not tested, but should work (hopefully)... 😄
sokra commentedon May 13, 2013
the source: https://github.com/webpack/webpack/blob/master/lib/ContextReplacementPlugin.js
jhnns commentedon May 13, 2013
Can this somehow be combined with the i18n plugin?
sokra commentedon May 13, 2013
With a (to be developed) tool that starts webpack for multiple languages... (to generate multiple bundles)
jhnns commentedon May 13, 2013
K I'll try my luck with the ContextReplacementPlugin 👍
masonicboom commentedon Oct 4, 2014
in the latest version of moment, the directory structure changed and you now need to target "locale" rather than "lang" in your regexes, e.g.
plugins: [ webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(de|pl)$/) ]jhnns commentedon Oct 6, 2014
Thx @masonicboom 👍
rafaeleyng commentedon May 31, 2016
Just in case somebody else come here and follow the link @jhnns provided, the actual line with the dynamic require is this one.
binki commentedon Sep 10, 2016
Shouldn’t webpack just create a chunk for each dynamically loadable language? The script already supports dynamic loading, probably to solve the exact problem webpack’s mishandling of it causes (it solves the problem of throwing irrelevant JavaScript that the browser will never call at the browser).
liqiang372 commentedon May 3, 2017
I came across similar dynamic require cases in amd
My confiuration for
ContextReplacementPluginisIt seems
ContextReplacementPlugindoes not support dependency array. Is any better way to do this?