sagold / handlebars-webpack-plugin

Renders your html-template at build time
162 stars 45 forks source link

HandlebarsPlugin + i18next + watchmode #94

Open imike57 opened 3 years ago

imike57 commented 3 years ago

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