Skip to content

Commit 5d4b14c

Browse files
authored
fix(unplugin-vue-i18n): improve wrong virtual module implementation (#155)
1 parent aef68a8 commit 5d4b14c

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

packages/unplugin-vue-i18n/src/index.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import type { CodeGenOptions, DevEnv } from '@intlify/bundle-utils'
2626
const INTLIFY_BUNDLE_IMPORT_ID = '@intlify/unplugin-vue-i18n/messages'
2727
const INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID =
2828
'@intlify/vite-plugin-vue-i18n/messages'
29+
const VIRTUAL_PREFIX = '\0'
30+
2931
const debug = createDebug('unplugin-vue-i18n')
3032

3133
export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
@@ -206,11 +208,11 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
206208
warn(
207209
`deprected '${INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID}', you should switch to '${INTLIFY_BUNDLE_IMPORT_ID}'`
208210
)
209-
return id
211+
return asVirtualId(id, meta.framework)
210212
}
211213

212214
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
213-
return id
215+
return asVirtualId(id, meta.framework)
214216
}
215217
},
216218

@@ -220,7 +222,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
220222
const { query } = parseVueRequest(id)
221223
if (
222224
[INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(
223-
id
225+
getVirtualId(id, meta.framework)
224226
) &&
225227
include
226228
) {
@@ -567,6 +569,25 @@ function getOptions(
567569
}
568570
}
569571

572+
function getVirtualId(
573+
id: string,
574+
framework: UnpluginContextMeta['framework'] = 'vite'
575+
) {
576+
// prettier-ignore
577+
return framework === 'vite'
578+
? id.startsWith(VIRTUAL_PREFIX)
579+
? id.slice(VIRTUAL_PREFIX.length)
580+
: ''
581+
: id
582+
}
583+
584+
function asVirtualId(
585+
id: string,
586+
framework: UnpluginContextMeta['framework'] = 'vite'
587+
) {
588+
return framework === 'vite' ? VIRTUAL_PREFIX + id : id
589+
}
590+
570591
export default unplugin
571592

572593
export * from './types'

0 commit comments

Comments
 (0)