I have the following function a file @/lang/index.js
:
async function fetchMessages(locale) {
const module = await import(/*
webpackChunkName: "lang/[request]",
webpackExclude: /index/
*/ `@/lang/${locale}`)
return module.default
}
I would like to hot-reload the modules imported by this function. I've tried a several different variations of module.hot.accept()
but without success.
Here's my hot reload code at the end of the same file that doesn't work:
if (process.env.NODE_ENV !== "production" && module.hot) {
module.hot.accept(["./en-US"], () => {
const { locale } = i18n
fetchMessages(locale).then((strings) => {
i18n.setLocaleMessage(locale, strings)
})
})
}
Any thoughts? I would like to hot-reload my language files when a change is detected.
Thanks!
index.js
not being the direct parent toen-US.js
. For eachimport()
expression a new "module" is created. If I use Webpack's internal identifier for that module ("./src/lang lazy recursive ^\\.\\/.*$ exclude: index"
) then it will work but the compiler will try to resolve that string to a module and throws an error. – Anthropophagi