intlify / bundle-tools

bundling for intlify i18n tools
MIT License
232 stars 37 forks source link

@intlify/unplugin-vue-i18n not support HMR with Static bundle importing #299

Open yoyoys opened 10 months ago

yoyoys commented 10 months ago

Reporting a bug?

Using "@intlify/unplugin-vue-i18n": "^1.2.0"

I've follow README.md's guide to setup my project like reproduction section. And I put locale files to src/locales/en.json, i18n works fine but dev server will refresh page everytime when I update the json file. And I got output like this:

11:39:17 AM [vite] page reload src/locales/en.json

Is my setting wrong? Thanks for help!

Expected behavior

When I saving only the text section update.

Reproduction

// vite.config.ts
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    UnoCSS(),
    VueI18nPlugin({
      include: [path.resolve(__dirname, './src/locales/**')],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
});
// main.ts
import messages from '@intlify/unplugin-vue-i18n/messages';

import App from './App.vue';

const app = createApp(App);

app.use(createPinia());
app.use(
  createI18n({
    legacy: false,
    locale: 'en',
    globalInjection: true,
    fallbackLocale: 'en',
    messages,
  }),
);

Issue Package

unplugin-vue-i18n

System Info

System:
    OS: macOS 13.4.1
    CPU: (8) arm64 Apple M1
    Memory: 96.44 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.0 - /usr/local/bin/node
    npm: 9.6.7 - /usr/local/bin/npm
    pnpm: 8.6.12 - ~/.npm-global/bin/pnpm
  Browsers:
    Chrome: 116.0.5845.187
    Safari: 16.5.2
  npmPackages:
    @intlify/unplugin-vue-i18n: ^1.2.0 => 1.2.0 
    vite: ^4.3.9 => 4.4.7 
    vue: ^3.3.4 => 3.3.4 
    vue-i18n: ^9.3.0 => 9.3.0

Screenshot

No response

Additional context

No response

Validations

cmdickson commented 7 months ago

It looks like this is blocked by Vite issue #12912. If the code that was reverted as part of the PR referenced in the ticket is re-applied, then virtual module updates can be accepted, including the @intlify/unplugin-vue-i18n/messages virtual module