@@ -11,7 +11,7 @@ import { promises as fs, existsSync } from 'fs'
11
11
import { isString } from '@intlify/shared'
12
12
import VitePlugin from '@intlify/vite-plugin-vue-i18n'
13
13
import { distDir } from './dirs'
14
- import { resolveLocales , isViteMode } from './utils'
14
+ import { resolveLocales , isViteMode , setupAliasTranspileOptions } from './utils'
15
15
16
16
import type { I18nOptions } from 'vue-i18n'
17
17
@@ -38,50 +38,36 @@ export function defineVueI18n(options: I18nOptions): I18nOptions {
38
38
return options
39
39
}
40
40
41
+ const MODULE_DEV_ENTRIES = {
42
+ '@intlify/shared' : '@intlify/shared/dist/shared.esm-bundler.js' ,
43
+ '@intlify/core-base' : '@intlify/core-base/dist/core-base.esm-bundler.js' ,
44
+ '@vue/devtools-api' : '@vue/devtools-api/lib/esm/index.js' ,
45
+ '@intlify/devtools-if' :
46
+ '@intlify/devtools-if/dist/devtools-if.esm-bundler.js' ,
47
+ 'vue-i18n' : 'vue-i18n/dist/vue-i18n.esm-bundler.js'
48
+ }
49
+
50
+ const MODULE_PROD_ENTRIES = {
51
+ '@intlify/shared' : '@intlify/shared/dist/shared.esm-bundler.js' ,
52
+ '@intlify/core-base' : '@intlify/core-base/dist/core-base.esm-bundler.js' ,
53
+ '@vue/devtools-api' : '@vue/devtools-api/lib/esm/index.js' ,
54
+ '@intlify/devtools-if' :
55
+ '@intlify/devtools-if/dist/devtools-if.esm-bundler.js' ,
56
+ 'vue-i18n' : 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
57
+ }
58
+
41
59
const IntlifyModule = defineNuxtModule < IntlifyModuleOptions > ( {
42
60
name : '@intlify/nuxt3' ,
43
61
configKey : 'intlify' ,
44
62
defaults : { } ,
45
63
async setup ( options , nuxt ) {
46
64
const _require = createRequire ( import . meta. url )
47
65
48
- const intlifySharedEntry = _require . resolve (
49
- '@intlify/shared/dist/shared.esm-bundler.js'
50
- )
51
- nuxt . options . alias [ '@intlify/shared' ] = intlifySharedEntry
52
- isViteMode ( nuxt . options ) &&
53
- nuxt . options . build . transpile . push ( '@intlify/shared' )
54
-
55
- // TODO: should use runtime-only for production
56
- const intlifyCoreBaseEntry = _require . resolve (
57
- '@intlify/core-base/dist/core-base.esm-bundler.js'
58
- )
59
- nuxt . options . alias [ '@intlify/core-base' ] = intlifyCoreBaseEntry
60
- isViteMode ( nuxt . options ) &&
61
- nuxt . options . build . transpile . push ( '@intlify/core-base' )
62
-
63
- // TODO: should not set vue-devtools for production
64
- const vueDevtoolsApiEntry = _require . resolve (
65
- '@vue/devtools-api/lib/esm/index.js'
66
- )
67
- nuxt . options . alias [ '@vue/devtools-api' ] = vueDevtoolsApiEntry
68
- isViteMode ( nuxt . options ) &&
69
- nuxt . options . build . transpile . push ( '@vue/devtools-api' )
70
-
71
- // TODO: should not set vue-devtools for production
72
- const intlifyDevtoolsIfEntry = _require . resolve (
73
- '@intlify/devtools-if/dist/devtools-if.esm-bundler.js'
74
- )
75
- nuxt . options . alias [ '@intlify/devtools-if' ] = intlifyDevtoolsIfEntry
76
- isViteMode ( nuxt . options ) &&
77
- nuxt . options . build . transpile . push ( '@intlify/devtools-if' )
78
-
79
- // TODO: should use runtime-only for production
80
- const vueI18nEntry = _require . resolve (
81
- 'vue-i18n/dist/vue-i18n.esm-bundler.js'
82
- )
83
- nuxt . options . alias [ 'vue-i18n' ] = vueI18nEntry
84
- isViteMode ( nuxt . options ) && nuxt . options . build . transpile . push ( 'vue-i18n' )
66
+ for ( const [ name , entry ] of Object . entries (
67
+ nuxt . options . dev ? MODULE_DEV_ENTRIES : MODULE_PROD_ENTRIES
68
+ ) ) {
69
+ setupAliasTranspileOptions ( nuxt , name , _require . resolve ( entry ) )
70
+ }
85
71
86
72
const localeDir = options . localeDir || 'locales'
87
73
const localePath = resolve ( nuxt . options . srcDir , localeDir )
@@ -154,10 +140,31 @@ export default { ${[...importMapper].map(i => `${JSON.stringify(i[0])}:${i[1]}`)
154
140
type : 'javascript/auto' ,
155
141
loader : '@intlify/vue-i18n-loader'
156
142
} )
143
+
144
+ if ( ! nuxt . options . dev ) {
145
+ // @ts -ignore TODO
146
+ ; ( config . resolve ?. alias as any ) [ 'vue-i18n' ] =
147
+ 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
148
+ }
149
+
150
+ // TODO: unplugin implementation
151
+ // config.plugins?.push(webpack.DefinePlugin, [
152
+ // {
153
+ // __VUE_I18N_LEGACY_API__: legacyApiFlag,
154
+ // __VUE_I18N_FULL_INSTALL__: installFlag,
155
+ // __VUE_I18N_PROD_DEVTOOLS__: 'false'
156
+ // }
157
+ // ])
157
158
} )
158
159
159
160
// install @intlify /vite-plugin-vue-i18n
160
161
extendViteConfig ( config => {
162
+ // TODO: unplugin implementation
163
+ if ( ! nuxt . options . dev ) {
164
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
+ ; ( config . resolve ?. alias as any ) [ 'vue-i18n' ] =
166
+ 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
167
+ }
161
168
// eslint-disable-next-line @typescript-eslint/no-explicit-any
162
169
const viteOptions : any = {
163
170
compositionOnly : false
0 commit comments