Skip to content

Commit

Permalink
refactor(vite): migrate to tsup (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1030 authored Apr 10, 2024
1 parent afe6f98 commit 1477592
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
19 changes: 0 additions & 19 deletions packages/vite/build.config.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/vite/esbuild-shims/cjs-shim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createRequire } from 'node:module'
import path from 'node:path'
import url from 'node:url'

globalThis.require = createRequire(import.meta.url)
globalThis.__filename = url.fileURLToPath(import.meta.url)
globalThis.__dirname = path.dirname(__filename)
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"node": ">=v14.21.3"
},
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub"
"build": "tsup",
"stub": "tsup --watch"
},
"peerDependencies": {
"vite": "^3.1.0 || ^4.0.0-0 || ^5.0.0-0"
Expand Down
35 changes: 35 additions & 0 deletions packages/vite/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entryPoints: [
'src/vite.ts',
],
// To avoid esbuild compile import.meta.url to import_meta.url
// See: https://github.com/vitejs/vite/issues/503
target: 'es2020',
clean: true,
format: ['esm', 'cjs'],
// Force esbuild to use .mjs extension for ESM output
outExtension({ format }) {
if (format === 'esm') {
return {
js: '.mjs',
dts: '.d.ts',
}
}
else if (format === 'cjs') {
return {
js: '.cjs',
dts: '.d.cts',
}
}
return {
js: '.js',
dts: '.d.ts',
}
},
// See: https://github.com/evanw/esbuild/issues/1921
inject: ['./esbuild-shims/cjs-shim.ts'],
dts: true,
shims: true,
})

0 comments on commit 1477592

Please sign in to comment.