一些选项可以通过 runtimeConfig
设置,以这种方式设置选项可以在构建后使用环境变量覆盖这些选项。
如果您想使用环境变量更改 支持的选项,您需要在 runtimeConfig.public.i18n
中设置这些选项。
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
// 留下您想通过 `runtimeConfig` 设置的选项
// baseUrl: 'https://example.com',
},
runtimeConfig: {
public: {
i18n: {
baseUrl: 'https://example.com',
domainLocales: {}
// 其他选项 ...
}
}
}
})
您可以在 Nuxt 文档 中了解更多关于它的工作原理。
runtimeConfig
中仅支持 可序列化值,以这种方式设置的选项可能不支持所有可用类型(如函数),这通常是使用默认配置时可能的。模块配置具有优先权,只有在未设置的情况下,才会使用通过 runtimeConfig
设置的选项。
可以使用 runtimeConfig
设置以下选项:
baseUrl
NUXT_PUBLIC_I18N_BASE_URL
此运行时配置选项与 baseUrl
模块选项相同。
baseUrl
模块选项允许您设置函数,但由于限制,运行时配置不允许。locales
locales[code].domain
NUXT_PUBLIC_I18N_DOMAIN_LOCALES_{code}_DOMAIN
此运行时配置选项允许覆盖在 locales
模块选项中设置的域。