Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose api #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
}
Loading