Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue i18n Advanced Optimization #131

Closed
YunYouJun opened this issue Jun 3, 2021 · 7 comments · Fixed by #152
Closed

Vue i18n Advanced Optimization #131

YunYouJun opened this issue Jun 3, 2021 · 7 comments · Fixed by #152

Comments

@YunYouJun
Copy link
Contributor

Hello, i just use this template and run it.

I can see a warning message in console.

image

vue-i18n.esm-bundler.js:46

You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.

Of course, we can turn off the warning like this.

// vite.config.ts
export default defineConfig({
  resolve: {
    alias: {
      "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
    },
  },
})

Do we need set boolean literals to replace feature flag globals? (Sorry, i can not understand what do we need to do.)


In addition, I read the documentation of vue-i18n.

Improve performance and reduce bundle size with runtime build only

Should we add it as part of the vite template?

export default defineConfig({
  // ...
  alias: {
    'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
  },
})

If you need, I can create a PR for it.

Thanks.

@userquin
Copy link
Member

userquin commented Jul 18, 2021

Just add these 2 options on VueI18n plugin, the plugin will change the module for you and so you don't have to map/resolve its internals:

    // https://github.com/intlify/vite-plugin-vue-i18n
    VueI18n({
      runtimeOnly: true,
      compositionOnly: true,
      include: [path.resolve(__dirname, 'locales/**')],
    }),

@YunYouJun
Copy link
Contributor Author

Okay, thank you, I see.

Should this be added as a default configuration for vitesse?

@userquin
Copy link
Member

@antfu I can make a PR, I have it prepared on local...

@userquin
Copy link
Member

Okay, thank you, I see.

Should this be added as a default configuration for vitesse?

You still have the warning on dev, since the plugin will omit the module replacement...

@userquin
Copy link
Member

@YunYouJun only on buid and runtimeOnly flag to true: https://github.com/intlify/bundle-tools/blob/main/packages/vite-plugin-vue-i18n/src/index.ts#L66

@userquin
Copy link
Member

userquin commented Jul 18, 2021

If you want to remove the warning on dev, you need to add the alias you propose...

@userquin
Copy link
Member

@antfu these 2 options are by default true so we dont need to change it, I just explicity set to true on the plugin to be used with vue 3, but for vue 2 will not work, I miss you change adding vue-demi so maybe we need to add some hint on docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants