Skip to content

Commit

Permalink
fix: fix module extname error for react
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Jun 24, 2024
1 parent ee73126 commit 6ee1e00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
14 changes: 5 additions & 9 deletions packages/varlet-icon-builder/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ export async function generateModule(options: GenerateModuleOptions) {
}

return getTransformResult({
filename,
content,
loader: framework === 'vue3' ? 'ts' : 'tsx',
format,
outputExtname,
})
}).then(({ code }) => ({
code,
filename: filename.replace('.ts', outputExtname).replace('.vue', outputExtname).replace('.tsx', outputExtname),
}))
}),
)

Expand Down Expand Up @@ -170,12 +171,7 @@ export default class ${removeExtname(filename)} {
export function generateIndexFile(dir: string) {
const filenames = fse.readdirSync(dir)
const content = filenames
.map(
(filename) =>
`export { default as ${removeExtname(filename)} } from './${
filename.endsWith('.ts') ? filename.replace('.ts', '') : filename
}'`,
)
.map((filename) => `export { default as ${removeExtname(filename)} } from './${filename.replace(/\.tsx?$/, '')}'`)
.join('\n')

fse.outputFileSync(resolve(dir, INDEX_FILE), content)
Expand Down
19 changes: 5 additions & 14 deletions packages/varlet-icon-builder/src/utils/esbuild.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import esbuild from 'esbuild'

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,
target: 'es2016',
format,
})
.then(({ code }) => ({
code,
filename: filename.replace('.ts', outputExtname).replace('.vue', outputExtname),
}))
return esbuild.transform(content, {
loader,
target: 'es2016',
format,
})
}

0 comments on commit 6ee1e00

Please sign in to comment.