-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(vite): migrate to tsup (#326)
- Loading branch information
1 parent
afe6f98
commit 1477592
Showing
4 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) |