@@ -16,14 +16,6 @@ import type { I18nNuxtContext } from './context'
16
16
const debug = createDebug ( '@nuxtjs/i18n:bundler' )
17
17
18
18
export async function extendBundler ( ctx : I18nNuxtContext , nuxt : Nuxt ) {
19
- const { options : nuxtOptions } = ctx
20
- const localePaths = [ ...new Set ( [ ...ctx . localeInfo . flatMap ( x => x . meta . map ( m => m . path ) ) ] ) ]
21
- const localeIncludePaths = localePaths . length ? localePaths : undefined
22
-
23
- const sourceMapOptions : BundlerPluginOptions = {
24
- sourcemap : ! ! nuxt . options . sourcemap . server || ! ! nuxt . options . sourcemap . client
25
- }
26
-
27
19
addTemplate ( {
28
20
write : true ,
29
21
filename : 'nuxt-i18n-logger.mjs' ,
@@ -34,9 +26,7 @@ export async function extendBundler(ctx: I18nNuxtContext, nuxt: Nuxt) {
34
26
35
27
return `
36
28
import { createConsola } from 'consola'
37
-
38
29
const debugLogger = createConsola({ level: ${ ctx . options . debug === 'verbose' ? 999 : 4 } }).withTag('i18n')
39
-
40
30
export function createLogger(label) {
41
31
return debugLogger.withTag(label)
42
32
}`
@@ -48,47 +38,50 @@ export function createLogger(label) {
48
38
/**
49
39
* shared plugins (nuxt/nitro)
50
40
*/
51
- const resourcePlugin = ResourcePlugin ( sourceMapOptions , ctx )
41
+ const pluginOptions : BundlerPluginOptions = {
42
+ sourcemap : ! ! nuxt . options . sourcemap . server || ! ! nuxt . options . sourcemap . client
43
+ }
44
+ const resourcePlugin = ResourcePlugin ( pluginOptions , ctx )
52
45
53
46
addBuildPlugin ( resourcePlugin )
54
-
55
47
nuxt . hook ( 'nitro:config' , async cfg => {
56
48
cfg . rollupConfig ! . plugins = ( await cfg . rollupConfig ! . plugins ) || [ ]
57
49
cfg . rollupConfig ! . plugins = toArray ( cfg . rollupConfig ! . plugins )
58
-
59
50
cfg . rollupConfig ! . plugins . push ( resourcePlugin . rollup ( ) )
60
51
} )
61
52
62
53
/**
63
- * shared plugins (webpack/vite )
54
+ * shared plugins (vite/ webpack/rspack )
64
55
*/
56
+ const { options } = ctx
57
+ const localePaths = [ ...new Set ( [ ...ctx . localeInfo . flatMap ( x => x . meta . map ( m => m . path ) ) ] ) ]
65
58
const vueI18nPluginOptions : PluginOptions = {
66
59
allowDynamic : true ,
67
- include : localeIncludePaths ,
68
- runtimeOnly : nuxtOptions . bundle . runtimeOnly ,
69
- fullInstall : nuxtOptions . bundle . fullInstall ,
70
- onlyLocales : nuxtOptions . bundle . onlyLocales ,
71
- escapeHtml : nuxtOptions . compilation . escapeHtml ,
72
- compositionOnly : nuxtOptions . bundle . compositionOnly ,
73
- strictMessage : nuxtOptions . compilation . strictMessage ,
74
- defaultSFCLang : nuxtOptions . customBlocks . defaultSFCLang ,
75
- globalSFCScope : nuxtOptions . customBlocks . globalSFCScope ,
76
- dropMessageCompiler : nuxtOptions . bundle . dropMessageCompiler ,
77
- optimizeTranslationDirective : nuxtOptions . bundle . optimizeTranslationDirective
60
+ include : localePaths . length ? localePaths : undefined ,
61
+ runtimeOnly : options . bundle . runtimeOnly ,
62
+ fullInstall : options . bundle . fullInstall ,
63
+ onlyLocales : options . bundle . onlyLocales ,
64
+ escapeHtml : options . compilation . escapeHtml ,
65
+ compositionOnly : options . bundle . compositionOnly ,
66
+ strictMessage : options . compilation . strictMessage ,
67
+ defaultSFCLang : options . customBlocks . defaultSFCLang ,
68
+ globalSFCScope : options . customBlocks . globalSFCScope ,
69
+ dropMessageCompiler : options . bundle . dropMessageCompiler ,
70
+ optimizeTranslationDirective : options . bundle . optimizeTranslationDirective
78
71
}
79
72
addBuildPlugin ( {
80
73
vite : ( ) => VueI18nPlugin . vite ( vueI18nPluginOptions ) ,
81
74
webpack : ( ) => VueI18nPlugin . webpack ( vueI18nPluginOptions )
82
75
} )
83
- addBuildPlugin ( TransformMacroPlugin ( sourceMapOptions ) )
84
- if ( nuxtOptions . experimental . autoImportTranslationFunctions ) {
85
- addBuildPlugin ( TransformI18nFunctionPlugin ( sourceMapOptions ) )
76
+ addBuildPlugin ( TransformMacroPlugin ( pluginOptions ) )
77
+ if ( options . experimental . autoImportTranslationFunctions ) {
78
+ addBuildPlugin ( TransformI18nFunctionPlugin ( pluginOptions ) )
86
79
}
87
80
88
81
const defineConfig = {
89
- ...getFeatureFlags ( nuxtOptions . bundle ) ,
90
- __DEBUG__ : String ( ! ! nuxtOptions . debug ) ,
91
- __TEST__ : String ( ! ! nuxtOptions . debug || nuxt . options . _i18nTest )
82
+ ...getFeatureFlags ( options . bundle ) ,
83
+ __DEBUG__ : String ( ! ! options . debug ) ,
84
+ __TEST__ : String ( ! ! options . debug || nuxt . options . _i18nTest )
92
85
}
93
86
/**
94
87
* webpack plugin
@@ -105,7 +98,7 @@ export function createLogger(label) {
105
98
/**
106
99
* rspack plugin
107
100
*/
108
- if ( nuxt . options . builder == '@nuxt/rspack-builder' ) {
101
+ if ( nuxt . options . builder === '@nuxt/rspack-builder' ) {
109
102
try {
110
103
const { rspack } = await import ( '@rspack/core' )
111
104
addRspackPlugin ( new rspack . DefinePlugin ( defineConfig ) )
0 commit comments