Skip to content

Commit

Permalink
fix(unplugin-vue-i18n): not work useVueI18nImportName option (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed May 17, 2024
1 parent b396066 commit 57e1a7b
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions packages/unplugin-vue-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
generateJSON,
generateYAML,
generateJavaScript,
checkInstallPackage,
getVueI18nVersion
checkInstallPackage
} from '@intlify/bundle-utils'
import { parse } from '@vue/compiler-sfc'
import { parseVueRequest, VueQuery } from './query'
Expand All @@ -39,7 +38,6 @@ const VIRTUAL_PREFIX = '\0'
const debug = createDebug('unplugin-vue-i18n')

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

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

// prettier-ignore
const getVueI18nAliasName = () =>
vueI18nVersion === '9'
installedPkg === 'petite-vue-i18n' && isBoolean(useVueI18nImportName) && useVueI18nImportName
? 'vue-i18n'
: vueI18nVersion === 'unknown' && installedPkg === 'petite-vue-i18n' && isBoolean(useVueI18nImportName) && useVueI18nImportName
? 'vue-i18n'
: installedPkg

const getVueI18nAliasPath = (
aliasName: string,
{ ssr = false, runtimeOnly = false }
) => {
return `${aliasName}/dist/${installedPkg}${runtimeOnly ? '.runtime' : ''}.${
: installedPkg

const getVueI18nAliasPath = ({ ssr = false, runtimeOnly = false }) => {
return `${installedPkg}/dist/${installedPkg}${runtimeOnly ? '.runtime' : ''}.${
!ssr ? 'esm-bundler.js' /* '.mjs' */ : 'node.mjs'
}`
}
Expand Down Expand Up @@ -168,27 +161,24 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
if (isArray(config.resolve!.alias)) {
config.resolve!.alias.push({
find: vueI18nAliasName,
replacement: getVueI18nAliasPath(vueI18nAliasName, {
replacement: getVueI18nAliasPath({
ssr: ssrBuild,
runtimeOnly
})
})
} else if (isObject(config.resolve!.alias)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(config.resolve!.alias as any)[vueI18nAliasName] =
getVueI18nAliasPath(vueI18nAliasName, {
getVueI18nAliasPath({
ssr: ssrBuild,
runtimeOnly
})
}
debug(
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
vueI18nAliasName,
{
ssr: ssrBuild,
runtimeOnly
}
)}`
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath({
ssr: ssrBuild,
runtimeOnly
})}`
)
} else if (
command === 'serve' &&
Expand Down Expand Up @@ -360,12 +350,12 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
if (isProduction) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(compiler.options.resolve!.alias as any)[vueI18nAliasName] =
getVueI18nAliasPath(vueI18nAliasName, {
getVueI18nAliasPath({
ssr: ssrBuild,
runtimeOnly
})
debug(
`set ${vueI18nAliasName}: ${getVueI18nAliasPath(vueI18nAliasName, {
`set ${vueI18nAliasName}: ${getVueI18nAliasPath({
ssr: ssrBuild,
runtimeOnly
})}`
Expand Down

0 comments on commit 57e1a7b

Please sign in to comment.