Answer the question
In order to leave comments, you need to log in
Is it possible to somehow use constants in the import'a path?
import default_locale from `~static/i18n/${config.lang}.json`
messages[config.lang] = default_locale
Answer the question
In order to leave comments, you need to log in
Only dynamic import()
supports the use of variables , while all files corresponding to the pattern get into the bundle.
If we are talking specifically about constants , then at the compilation webpack
stage it still does not know what you have in there config
. It doesn't run your code - it builds it.
If your config file is static, then you can include it in the webpack config itself and make there, for example, an alias of the form:
`~static/i18n/CONFIG_LANG.json`: path.resolve(`./static/i18n/${config.lang}.json`)
and in the code, respectively, write:import default_locale from `~static/i18n/CONFIG_LANG.json`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question