@@ -4,7 +4,6 @@ import createDebug from 'debug'
4
4
import fg from 'fast-glob'
5
5
import {
6
6
isArray ,
7
- isObject ,
8
7
isEmptyObject ,
9
8
isString ,
10
9
isNumber ,
@@ -16,12 +15,11 @@ import { createFilter } from '@rollup/pluginutils'
16
15
import {
17
16
generateJSON ,
18
17
generateYAML ,
19
- generateJavaScript ,
20
- checkInstallPackage
18
+ generateJavaScript
21
19
} from '@intlify/bundle-utils'
22
20
import { parse } from '@vue/compiler-sfc'
23
21
import { parseVueRequest , VueQuery } from './query'
24
- import { getRaw , warn , error , raiseError } from './utils'
22
+ import { getRaw , warn , error , raiseError , checkInstallPackage } from './utils'
25
23
26
24
import type { RawSourceMap } from 'source-map-js'
27
25
import type {
@@ -37,7 +35,7 @@ const VIRTUAL_PREFIX = '\0'
37
35
38
36
const debug = createDebug ( 'unplugin-vue-i18n' )
39
37
40
- const installedPkg = checkInstallPackage ( '@intlify/unplugin-vue-i18n' , debug )
38
+ const installedPkgInfo = checkInstallPackage ( debug )
41
39
42
40
export const unplugin = createUnplugin < PluginOptions > ( ( options = { } , meta ) => {
43
41
debug ( 'plugin options:' , options , meta . framework )
@@ -84,15 +82,15 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
84
82
debug ( 'dropMessageCompiler' , dropMessageCompiler )
85
83
86
84
// prettier-ignore
87
- const compositionOnly = installedPkg === 'vue-i18n'
85
+ const compositionOnly = installedPkgInfo . pkg === 'vue-i18n'
88
86
? isBoolean ( options . compositionOnly )
89
87
? options . compositionOnly
90
88
: true
91
89
: true
92
90
debug ( 'compositionOnly' , compositionOnly )
93
91
94
92
// prettier-ignore
95
- const fullInstall = installedPkg === 'vue-i18n'
93
+ const fullInstall = installedPkgInfo . pkg === 'vue-i18n'
96
94
? isBoolean ( options . fullInstall )
97
95
? options . fullInstall
98
96
: true
@@ -102,20 +100,8 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
102
100
const ssrBuild = ! ! options . ssr
103
101
debug ( 'ssr' , ssrBuild )
104
102
105
- const useVueI18nImportName = options . useVueI18nImportName
106
- if ( useVueI18nImportName != null ) {
107
- warn ( `'useVueI18nImportName' option is experimental` )
108
- }
109
- debug ( 'useVueI18nImportName' , useVueI18nImportName )
110
-
111
- // prettier-ignore
112
- const getVueI18nAliasName = ( ) =>
113
- installedPkg === 'petite-vue-i18n' && isBoolean ( useVueI18nImportName ) && useVueI18nImportName
114
- ? 'vue-i18n'
115
- : installedPkg
116
-
117
103
const getVueI18nAliasPath = ( { ssr = false , runtimeOnly = false } ) => {
118
- return `${ installedPkg } /dist/${ installedPkg } ${ runtimeOnly ? '.runtime' : '' } .${
104
+ return `${ installedPkgInfo . alias } /dist/${ installedPkgInfo . pkg } ${ runtimeOnly ? '.runtime' : '' } .${
119
105
! ssr ? 'esm-bundler.js' /* '.mjs' */ : 'node.mjs'
120
106
} `
121
107
}
@@ -134,7 +120,8 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
134
120
let isProduction = false
135
121
let sourceMap = false
136
122
137
- const vueI18nAliasName = getVueI18nAliasName ( )
123
+ const vueI18nAliasName = installedPkgInfo . alias
124
+ debug ( `vue-i18n alias name: ${ vueI18nAliasName } ` )
138
125
139
126
return {
140
127
name : 'unplugin-vue-i18n' ,
@@ -150,73 +137,30 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
150
137
enforce : meta . framework === 'vite' ? 'pre' : 'post' ,
151
138
152
139
vite : {
153
- config ( config , { command } ) {
154
- config . resolve = normalizeConfigResolveAlias (
155
- config . resolve ,
156
- meta . framework
157
- )
140
+ config ( ) {
141
+ const defineConfig = {
142
+ define : {
143
+ __VUE_I18N_LEGACY_API__ : ! compositionOnly ,
144
+ __VUE_I18N_FULL_INSTALL__ : fullInstall ,
145
+ __INTLIFY_DROP_MESSAGE_COMPILER__ : dropMessageCompiler ,
146
+ __VUE_I18N_PROD_DEVTOOLS__ : false
147
+ }
148
+ }
149
+ debug ( 'define Config:' , defineConfig )
158
150
159
- if ( command === 'build' ) {
160
- debug ( `vue-i18n alias name: ${ vueI18nAliasName } ` )
161
- if ( isArray ( config . resolve ! . alias ) ) {
162
- config . resolve ! . alias . push ( {
163
- find : vueI18nAliasName ,
164
- replacement : getVueI18nAliasPath ( {
165
- ssr : ssrBuild ,
166
- runtimeOnly
167
- } )
168
- } )
169
- } else if ( isObject ( config . resolve ! . alias ) ) {
170
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
- ; ( config . resolve ! . alias as any ) [ vueI18nAliasName ] =
172
- getVueI18nAliasPath ( {
151
+ const aliasConfig = {
152
+ resolve : {
153
+ alias : {
154
+ [ vueI18nAliasName ] : getVueI18nAliasPath ( {
173
155
ssr : ssrBuild ,
174
156
runtimeOnly
175
157
} )
158
+ }
176
159
}
177
- debug (
178
- `set ${ vueI18nAliasName } runtime only: ${ getVueI18nAliasPath ( {
179
- ssr : ssrBuild ,
180
- runtimeOnly
181
- } ) } `
182
- )
183
- } else if (
184
- command === 'serve' &&
185
- installedPkg === 'petite-vue-i18n' &&
186
- useVueI18nImportName
187
- ) {
188
- config . resolve = normalizeConfigResolveAlias (
189
- config . resolve ,
190
- meta . framework
191
- )
192
- if ( isArray ( config . resolve ! . alias ) ) {
193
- config . resolve ! . alias . push ( {
194
- find : vueI18nAliasName ,
195
- replacement : `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`
196
- } )
197
- } else {
198
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
199
- ; ( config . resolve ! . alias as any ) [ vueI18nAliasName ] =
200
- `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`
201
- }
202
- debug ( `petite-vue-i18n alias name: ${ vueI18nAliasName } ` )
203
160
}
161
+ debug ( 'alias Config:' , aliasConfig )
204
162
205
- config . define = config . define || { }
206
- config . define [ '__VUE_I18N_LEGACY_API__' ] = ! compositionOnly
207
- debug (
208
- `set __VUE_I18N_LEGACY_API__ is '${ config . define [ '__VUE_I18N_LEGACY_API__' ] } '`
209
- )
210
- config . define [ '__VUE_I18N_FULL_INSTALL__' ] = fullInstall
211
- debug (
212
- `set __VUE_I18N_FULL_INSTALL__ is '${ config . define [ '__VUE_I18N_FULL_INSTALL__' ] } '`
213
- )
214
- config . define [ '__INTLIFY_DROP_MESSAGE_COMPILER__' ] = dropMessageCompiler
215
- debug (
216
- `set __INTLIFY_DROP_MESSAGE_COMPILER__ is '${ config . define [ '__INTLIFY_DROP_MESSAGE_COMPILER__' ] } '`
217
- )
218
-
219
- config . define [ '__VUE_I18N_PROD_DEVTOOLS__' ] = false
163
+ return assign ( defineConfig , aliasConfig )
220
164
} ,
221
165
222
166
configResolved ( config ) {
@@ -346,30 +290,18 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
346
290
compiler . options . resolve ,
347
291
meta . framework
348
292
)
349
-
350
- if ( isProduction ) {
351
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
352
- ; ( compiler . options . resolve ! . alias as any ) [ vueI18nAliasName ] =
353
- getVueI18nAliasPath ( {
354
- ssr : ssrBuild ,
355
- runtimeOnly
356
- } )
357
- debug (
358
- `set ${ vueI18nAliasName } : ${ getVueI18nAliasPath ( {
359
- ssr : ssrBuild ,
360
- runtimeOnly
361
- } ) } `
362
- )
363
- } else if (
364
- ! isProduction &&
365
- installedPkg === 'petite-vue-i18n' &&
366
- useVueI18nImportName
367
- ) {
368
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
369
- ; ( compiler . options . resolve ! . alias as any ) [ vueI18nAliasName ] =
370
- `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`
371
- debug ( `petite-vue-i18n alias name: ${ vueI18nAliasName } ` )
372
- }
293
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
294
+ ; ( compiler . options . resolve ! . alias as any ) [ vueI18nAliasName ] =
295
+ getVueI18nAliasPath ( {
296
+ ssr : ssrBuild ,
297
+ runtimeOnly
298
+ } )
299
+ debug (
300
+ `set ${ vueI18nAliasName } : ${ getVueI18nAliasPath ( {
301
+ ssr : ssrBuild ,
302
+ runtimeOnly
303
+ } ) } `
304
+ )
373
305
374
306
loadWebpack ( ) . then ( webpack => {
375
307
if ( webpack ) {
0 commit comments