Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Jun 24, 2024
1 parent 5d60dfa commit ee73126
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
8 changes: 7 additions & 1 deletion packages/varlet-icon-builder/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ export async function generateModule(options: GenerateModuleOptions) {
content = content.replace(/\.vue/g, outputExtname)
}

return getTransformResult(content, framework, format, filename, outputExtname)
return getTransformResult({
filename,
content,
loader: framework === 'vue3' ? 'ts' : 'tsx',
format,
outputExtname,
})
}),
)

Expand Down
34 changes: 14 additions & 20 deletions packages/varlet-icon-builder/src/utils/esbuild.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { GenerateFramework } from './config.js'
import esbuild from 'esbuild'

export function getEsbuildLoader(framework: GenerateFramework) {
switch (framework) {
case GenerateFramework.vue3:
return 'ts'
case GenerateFramework.react:
return 'tsx'
default:
return 'ts'
}
}

export function getTransformResult(
content: string,
framework: GenerateFramework,
format: 'cjs' | 'esm',
filename: string,
outputExtname: string,
) {
export function getTransformResult({
filename,
content,
loader,
format,
outputExtname,
}: {
filename: string
content: string
loader: 'ts' | 'tsx'
format: 'cjs' | 'esm'
outputExtname: string
}) {
return esbuild
.transform(content, {
loader: getEsbuildLoader(framework),
loader,
target: 'es2016',
format,
})
Expand Down

0 comments on commit ee73126

Please sign in to comment.