Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions packages/unplugin-vue-i18n/src/core/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {
checkVuePlugin,
error,
getVitePlugin,
getVitePluginTransform,
overrideVitePluginTransform,
raiseError,
resolveNamespace,
warn
Expand Down Expand Up @@ -138,24 +136,11 @@ export function resourcePlugin(
`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`
)

/**
* NOTE:
* For the native rolldown plugin, we need to change to another solution from the current workaround.
* Currently, the rolldown team and vite team are discussing this issue.
* https://github.com/vitejs/rolldown-vite/issues/120
*/

// json transform handling
const jsonPlugin = getVitePlugin(config, 'vite:json')
if (jsonPlugin) {
// saving `vite:json` plugin instance
const [orgTransform, transformWay] =
getVitePluginTransform(jsonPlugin)
if (!orgTransform) {
throw new Error('vite:json plugin not found!')
}

async function overrideViteJsonPlugin(code: string, id: string) {
const orgTransform = jsonPlugin.transform // backup @rollup/plugin-json
jsonPlugin.transform = async function (code: string, id: string) {
if (!/\.json$/.test(id) || filter(id)) {
return
}
Expand All @@ -177,13 +162,6 @@ export function resourcePlugin(
// @ts-expect-error
return orgTransform!.apply(this, [code, id])
}

// override `vite:json` plugin transform function
overrideVitePluginTransform(
jsonPlugin,
overrideViteJsonPlugin,
transformWay!
)
}

/**
Expand Down
28 changes: 0 additions & 28 deletions packages/unplugin-vue-i18n/src/utils/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,6 @@ export function getVitePlugin(
return config.plugins.find(p => p.name === name) as RollupPlugin
}

export function getVitePluginTransform(
plugin: RollupPlugin
): [RollupPlugin['transform'], 'handler' | 'transform' | undefined] {
if (plugin.transform) {
return 'handler' in plugin.transform
? [plugin.transform.handler, 'handler']
: [plugin.transform, 'transform']
} else {
return [undefined, undefined]
}
}

// TODO: `override` type, we need more strict type
export function overrideVitePluginTransform(
plugin: RollupPlugin,
override: Function,
to: 'handler' | 'transform'
): void {
if (plugin.transform == undefined) {
throw new Error('plugin.transform is undefined')
}
if (to === 'handler' && 'handler' in plugin.transform) {
plugin.transform.handler = override as typeof plugin.transform.handler
} else {
plugin.transform = override as typeof plugin.transform
}
}

export function checkVuePlugin(vuePlugin: RollupPlugin | null): boolean {
if (vuePlugin == null || !vuePlugin.api) {
error(
Expand Down