1+ /* eslint-disable @typescript-eslint/no-floating-promises */
12import createDebug from 'debug'
23import { resolve } from 'pathe'
34import { extendViteConfig , addWebpackPlugin , addBuildPlugin } from '@nuxt/kit'
45import VueI18nPlugin from '@intlify/unplugin-vue-i18n'
6+ import { toArray } from './utils'
57import { TransformMacroPlugin } from './transform/macros'
68import { ResourcePlugin } from './transform/resource'
9+ import { i18nVirtualLoggerPlugin } from './virtual-logger'
710import { TransformI18nFunctionPlugin } from './transform/i18n-function-injection'
811import { getLayerLangPaths } from './layers'
912
@@ -14,7 +17,8 @@ import type { I18nNuxtContext } from './context'
1417
1518const debug = createDebug ( '@nuxtjs/i18n:bundler' )
1619
17- export async function extendBundler ( { options : nuxtOptions } : I18nNuxtContext , nuxt : Nuxt ) {
20+ export async function extendBundler ( ctx : I18nNuxtContext , nuxt : Nuxt ) {
21+ const { options : nuxtOptions } = ctx
1822 const langPaths = getLayerLangPaths ( nuxt )
1923 debug ( 'langPaths -' , langPaths )
2024 const i18nModulePaths =
@@ -27,6 +31,26 @@ export async function extendBundler({ options: nuxtOptions }: I18nNuxtContext, n
2731 sourcemap : ! ! nuxt . options . sourcemap . server || ! ! nuxt . options . sourcemap . client
2832 }
2933
34+ /**
35+ * shared plugins (nuxt/nitro)
36+ */
37+ const loggerPlugin = i18nVirtualLoggerPlugin ( ctx . options . debug )
38+ const resourcePlugin = ResourcePlugin ( sourceMapOptions , ctx )
39+
40+ addBuildPlugin ( loggerPlugin )
41+ addBuildPlugin ( resourcePlugin )
42+
43+ nuxt . hook ( 'nitro:config' , async cfg => {
44+ cfg . rollupConfig ! . plugins = ( await cfg . rollupConfig ! . plugins ) || [ ]
45+ cfg . rollupConfig ! . plugins = toArray ( cfg . rollupConfig ! . plugins )
46+
47+ cfg . rollupConfig ! . plugins . push ( loggerPlugin . rollup ( ) )
48+ cfg . rollupConfig ! . plugins . push ( resourcePlugin . rollup ( ) )
49+ } )
50+
51+ /**
52+ * shared plugins (webpack/vite)
53+ */
3054 const vueI18nPluginOptions : PluginOptions = {
3155 allowDynamic : true ,
3256 include : localeIncludePaths ,
@@ -41,16 +65,11 @@ export async function extendBundler({ options: nuxtOptions }: I18nNuxtContext, n
4165 dropMessageCompiler : nuxtOptions . bundle . dropMessageCompiler ,
4266 optimizeTranslationDirective : nuxtOptions . bundle . optimizeTranslationDirective
4367 }
44-
45- /**
46- * shared plugins
47- */
4868 addBuildPlugin ( {
4969 vite : ( ) => VueI18nPlugin . vite ( vueI18nPluginOptions ) ,
5070 webpack : ( ) => VueI18nPlugin . webpack ( vueI18nPluginOptions )
5171 } )
5272 addBuildPlugin ( TransformMacroPlugin ( sourceMapOptions ) )
53- addBuildPlugin ( ResourcePlugin ( sourceMapOptions ) )
5473 if ( nuxtOptions . experimental . autoImportTranslationFunctions ) {
5574 addBuildPlugin ( TransformI18nFunctionPlugin ( sourceMapOptions ) )
5675 }
0 commit comments