Skip to content

Commit

Permalink
feat: expose api
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanzmj committed Oct 9, 2024
1 parent ab5c0f5 commit 2eb24eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function transformVueJsxVapor(
inline: true,
isTS: id.endsWith('tsx'),
filename: id,
...options?.compile,
...options?.compilerOptions,
},
)
vaporHelpers.forEach((helper) => importSet.add(helper))
Expand Down
33 changes: 29 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
import { type UnpluginFactory, createUnplugin } from 'unplugin'
import { createFilter, transformWithEsbuild } from 'vite'
import { shallowRef } from 'vue'
import { version } from '../package.json'
import { transformVueJsxVapor } from './core/transform'
import type { Options } from './types'

export const unpluginFactory: UnpluginFactory<Options | undefined> = (
options = {},
rawOptions = {},
) => {
const options = shallowRef<Options>({
include: /\.[jt]sx$/,
...rawOptions,
})

const api = {
get options() {
return options.value
},
set options(value) {
options.value = value
},
version,
}

const transformInclude = createFilter(
options?.include || /\.[jt]sx$/,
options?.exclude,
options.value.include,
options.value.exclude,
)

return [
{
name: 'unplugin-vue-jsx-vapor',
vite: {
api,
config(config) {
return {
// only apply esbuild to ts files
Expand All @@ -31,9 +50,15 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
}
},
},
rollup: {
api,
},
rolldown: {
api,
},
transformInclude,
transform(code, id) {
return transformVueJsxVapor(code, id, options)
return transformVueJsxVapor(code, id, options.value)
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface Options {
// define your plugin options here
include?: FilterPattern
exclude?: FilterPattern
compile?: CompilerOptions
compilerOptions?: CompilerOptions
}

0 comments on commit 2eb24eb

Please sign in to comment.