nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.75k stars 483 forks source link

Nuxt's entry file grows too large with adding more languages and pages #2738

Closed anti-captcha closed 9 months ago

anti-captcha commented 9 months ago

My Nuxt 3 entry file grew to 800kb, 700kb of which are repeating lines like this: { name: (v == null ? void 0 : v.name) ?? "apidoc-methods-getResellerData___vi", path: (v == null ? void 0 : v.path) ?? "/vi/apidoc/methods/getResellerData", meta: v || {}, alias: (v == null ? void 0 : v.alias) || [], redirect: (v == null ? void 0 : v.redirect) || void 0, component: () => r(() => import("./getResellerData.712f70af.js"), ["./getResellerData.712f70af.js", "./stores.77821267.js", "./components.1ed091d0.js", "./components.ab028930.css"], import.meta.url).then(i => i.default || i) }, { name: (v == null ? void 0 : v.name) ?? "apidoc-methods-getResellerData___ur", path: (v == null ? void 0 : v.path) ?? "/ur/apidoc/methods/getResellerData", meta: v || {}, alias: (v == null ? void 0 : v.alias) || [], redirect: (v == null ? void 0 : v.redirect) || void 0, component: () => r(() => import("./getResellerData.712f70af.js"), ["./getResellerData.712f70af.js", "./stores.77821267.js", "./components.1ed091d0.js", "./components.ab028930.css"], import.meta.url).then(i => i.default || i) }, { name: (v == null ? void 0 : v.name) ?? "apidoc-methods-getResellerData___uk", path: (v == null ? void 0 : v.path) ?? "/uk/apidoc/methods/getResellerData", meta: v || {}, alias: (v == null ? void 0 : v.alias) || [], redirect: (v == null ? void 0 : v.redirect) || void 0, component: () => r(() => import("./getResellerData.712f70af.js"), ["./getResellerData.712f70af.js", "./stores.77821267.js", "./components.1ed091d0.js", "./components.ab028930.css"], import.meta.url).then(i => i.default || i) }, { name: (v == null ? void 0 : v.name) ?? "apidoc-methods-getResellerData___id", path: (v == null ? void 0 : v.path) ?? "/id/apidoc/methods/getResellerData", meta: v || {}, alias: (v == null ? void 0 : v.alias) || [], redirect: (v == null ? void 0 : v.redirect) || void 0, component: () => r(() => import("./getResellerData.712f70af.js"), ["./getResellerData.712f70af.js", "./stores.77821267.js", "./components.1ed091d0.js", "./components.ab028930.css"], import.meta.url).then(i => i.default || i) }

So for every X amount of languages and Y amount of pages Nuxt generates X*Y records for each page, similar to above. Is there a way to reduce the size of the entry file?

BobbieGoede commented 9 months ago

You're right that the module generates routes for each page in each language depending on the configured strategy, as far as I'm aware there's no way to reduce this further.

Without seeing your project I can't tell if the repeated null checks in your entry file sample are necessary. I think if these pages are not using definePageMeta these checks should be tree-shaked out of the build, which should bring your entry file down a bit.

I think when/if this https://github.com/nuxt/nuxt/pull/25210 gets merged it may also be an option to bring down the build size further.

anti-captcha commented 9 months ago

Thank you for your quick answer. Yes I'm using definePageMeta for defining layouts.

BobbieGoede commented 9 months ago

Since the file size of the generated routes is mostly dependent on the implementation upstream in Nuxt and Vue Router I'll be closing this. I do have an idea on how we can reduce this from Nuxt's side, so I'll look into that and refer to this issue if it pans out 😄.