Skip to content

Commit 57e1a7b

Browse files
authored
fix(unplugin-vue-i18n): not work useVueI18nImportName option (#371)
1 parent b396066 commit 57e1a7b

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import {
1717
generateJSON,
1818
generateYAML,
1919
generateJavaScript,
20-
checkInstallPackage,
21-
getVueI18nVersion
20+
checkInstallPackage
2221
} from '@intlify/bundle-utils'
2322
import { parse } from '@vue/compiler-sfc'
2423
import { parseVueRequest, VueQuery } from './query'
@@ -39,7 +38,6 @@ const VIRTUAL_PREFIX = '\0'
3938
const debug = createDebug('unplugin-vue-i18n')
4039

4140
const installedPkg = checkInstallPackage('@intlify/unplugin-vue-i18n', debug)
42-
const vueI18nVersion = getVueI18nVersion(debug)
4341

4442
export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
4543
debug('plugin options:', options, meta.framework)
@@ -112,17 +110,12 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
112110

113111
// prettier-ignore
114112
const getVueI18nAliasName = () =>
115-
vueI18nVersion === '9'
113+
installedPkg === 'petite-vue-i18n' && isBoolean(useVueI18nImportName) && useVueI18nImportName
116114
? 'vue-i18n'
117-
: vueI18nVersion === 'unknown' && installedPkg === 'petite-vue-i18n' && isBoolean(useVueI18nImportName) && useVueI18nImportName
118-
? 'vue-i18n'
119-
: installedPkg
120-
121-
const getVueI18nAliasPath = (
122-
aliasName: string,
123-
{ ssr = false, runtimeOnly = false }
124-
) => {
125-
return `${aliasName}/dist/${installedPkg}${runtimeOnly ? '.runtime' : ''}.${
115+
: installedPkg
116+
117+
const getVueI18nAliasPath = ({ ssr = false, runtimeOnly = false }) => {
118+
return `${installedPkg}/dist/${installedPkg}${runtimeOnly ? '.runtime' : ''}.${
126119
!ssr ? 'esm-bundler.js' /* '.mjs' */ : 'node.mjs'
127120
}`
128121
}
@@ -168,27 +161,24 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
168161
if (isArray(config.resolve!.alias)) {
169162
config.resolve!.alias.push({
170163
find: vueI18nAliasName,
171-
replacement: getVueI18nAliasPath(vueI18nAliasName, {
164+
replacement: getVueI18nAliasPath({
172165
ssr: ssrBuild,
173166
runtimeOnly
174167
})
175168
})
176169
} else if (isObject(config.resolve!.alias)) {
177170
// eslint-disable-next-line @typescript-eslint/no-explicit-any
178171
;(config.resolve!.alias as any)[vueI18nAliasName] =
179-
getVueI18nAliasPath(vueI18nAliasName, {
172+
getVueI18nAliasPath({
180173
ssr: ssrBuild,
181174
runtimeOnly
182175
})
183176
}
184177
debug(
185-
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
186-
vueI18nAliasName,
187-
{
188-
ssr: ssrBuild,
189-
runtimeOnly
190-
}
191-
)}`
178+
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath({
179+
ssr: ssrBuild,
180+
runtimeOnly
181+
})}`
192182
)
193183
} else if (
194184
command === 'serve' &&
@@ -360,12 +350,12 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
360350
if (isProduction) {
361351
// eslint-disable-next-line @typescript-eslint/no-explicit-any
362352
;(compiler.options.resolve!.alias as any)[vueI18nAliasName] =
363-
getVueI18nAliasPath(vueI18nAliasName, {
353+
getVueI18nAliasPath({
364354
ssr: ssrBuild,
365355
runtimeOnly
366356
})
367357
debug(
368-
`set ${vueI18nAliasName}: ${getVueI18nAliasPath(vueI18nAliasName, {
358+
`set ${vueI18nAliasName}: ${getVueI18nAliasPath({
369359
ssr: ssrBuild,
370360
runtimeOnly
371361
})}`

0 commit comments

Comments
 (0)