handlebars-webpack-plugin icon indicating copy to clipboard operation
handlebars-webpack-plugin copied to clipboard

HandlebarsPlugin + i18next + watchmode

Open imike57 opened this issue 3 years ago • 0 comments

I am looking for a solution to use HandlebarsPlugin with i18next and the watch mode of webpack.

Currently I am initializing i18next at the top of my webpack configuration. I also use HandlebarsI18n helpers to manage translations.

  i18next.init({
      lng: 'en', 
      debug: true,
      resources: {
          en: {
              translation : require('../locales/en/translation.json')
          },
          fr: {
              translation : require('../locales/fr/translation.json')
          }
      }
  });

It works fine if I'm not in watch mode

I currently have two problems.

  1. When I modify an hbs file, the watch effectively relaunches the build. However, the translations are not reloaded. I guess HandlebarsPlugin do not reinit its configuration.
  2. When I modify a json translation file, the watch does not restart the build.

I tried to restart the initialization of i18next in the different hooks offered by HandlebarsPlugin (onBeforeSetup, onBeforeAddPartials, onBeforeCompile, ...) But it doesn't work.

Do you have any idea how to reload the translations with webpack's watch mode?

I also tried the plugins: prebuild-webpack-plugin and before-build-webpack without success

Thank's for your help

imike57 avatar Jul 08 '21 09:07 imike57