Skip to content

Commit 6328ef2

Browse files
sapphi-redhi-ogawa
andauthored
build: use tsdown for plugin-react-swc (#555)
Co-authored-by: Hiroshi Ogawa <[email protected]>
1 parent 9ff1075 commit 6328ef2

File tree

7 files changed

+127
-130
lines changed

7 files changed

+127
-130
lines changed

packages/plugin-react-swc/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"type": "module",
1616
"private": true,
1717
"scripts": {
18-
"dev": "tsx scripts/bundle.ts --dev",
19-
"build": "tsx scripts/bundle.ts",
18+
"dev": "tsdown --watch",
19+
"build": "tsdown",
2020
"test": "playwright test"
2121
},
2222
"repository": {
@@ -40,10 +40,9 @@
4040
"@types/fs-extra": "^11.0.4",
4141
"@types/node": "^22.16.0",
4242
"@vitejs/react-common": "workspace:*",
43-
"esbuild": "^0.25.5",
4443
"fs-extra": "^11.3.0",
45-
"picocolors": "^1.1.1",
4644
"prettier": "^3.0.3",
45+
"tsdown": "^0.12.9",
4746
"typescript": "^5.8.3"
4847
}
4948
}

packages/plugin-react-swc/scripts/bundle.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,7 @@
11
{
2-
"include": [
3-
"src",
4-
"scripts",
5-
"playwright.config.ts",
6-
"playground/utils.ts",
7-
"playground/*/__tests__"
8-
],
9-
"compilerOptions": {
10-
/* Target node 22 */
11-
"module": "ESNext",
12-
"lib": ["ES2023", "DOM"],
13-
"target": "ES2023",
14-
"skipLibCheck": true,
15-
16-
/* Bundler mode */
17-
"moduleResolution": "bundler",
18-
"allowImportingTsExtensions": true,
19-
"verbatimModuleSyntax": true,
20-
"noEmit": true,
21-
22-
/* Linting */
23-
"strict": true,
24-
"noUnusedLocals": true,
25-
"noUnusedParameters": true,
26-
"noFallthroughCasesInSwitch": true,
27-
"useUnknownInCatchVariables": true,
28-
"noUncheckedSideEffectImports": true,
29-
"noPropertyAccessFromIndexSignature": true
30-
}
2+
"include": [],
3+
"references": [
4+
{ "path": "./tsconfig.src.json" },
5+
{ "path": "./tsconfig.test.json" }
6+
]
317
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"include": ["src"],
3+
"compilerOptions": {
4+
/* Target node 22 */
5+
"module": "ESNext",
6+
"lib": ["ES2023", "DOM"],
7+
"target": "ES2023",
8+
"skipLibCheck": true,
9+
10+
/* Bundler mode */
11+
"moduleResolution": "bundler",
12+
"allowImportingTsExtensions": true,
13+
"verbatimModuleSyntax": true,
14+
"noEmit": true,
15+
"declaration": true,
16+
"isolatedDeclarations": true,
17+
18+
/* Linting */
19+
"strict": true,
20+
"noUnusedLocals": true,
21+
"noUnusedParameters": true,
22+
"noFallthroughCasesInSwitch": true,
23+
"useUnknownInCatchVariables": true,
24+
"noUncheckedSideEffectImports": true,
25+
"noPropertyAccessFromIndexSignature": true
26+
}
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"include": ["playwright.config.ts", "playground"],
3+
"compilerOptions": {
4+
/* Target node 22 */
5+
"module": "ESNext",
6+
"lib": ["ES2023", "DOM"],
7+
"target": "ES2023",
8+
"skipLibCheck": true,
9+
10+
/* Bundler mode */
11+
"moduleResolution": "bundler",
12+
"allowImportingTsExtensions": true,
13+
"verbatimModuleSyntax": true,
14+
"noEmit": true,
15+
16+
/* Linting */
17+
"strict": true,
18+
"noUnusedLocals": true,
19+
"noUnusedParameters": true,
20+
"noFallthroughCasesInSwitch": true,
21+
"useUnknownInCatchVariables": true,
22+
"noUncheckedSideEffectImports": true,
23+
"noPropertyAccessFromIndexSignature": true
24+
}
25+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { writeFileSync } from 'node:fs'
2+
import { defineConfig } from 'tsdown'
3+
import packageJSON from './package.json' with { type: 'json' }
4+
5+
export default defineConfig({
6+
entry: 'src/index.ts',
7+
format: ['esm', 'cjs'],
8+
dts: true,
9+
tsconfig: './tsconfig.src.json', // https://github.com/sxzz/rolldown-plugin-dts/issues/55
10+
copy: [
11+
{
12+
from: 'node_modules/@vitejs/react-common/refresh-runtime.js',
13+
to: 'dist/refresh-runtime.js',
14+
},
15+
{
16+
from: 'LICENSE',
17+
to: 'dist/LICENSE',
18+
},
19+
{
20+
from: 'README.md',
21+
to: 'dist/README.md',
22+
},
23+
],
24+
outputOptions(outputOpts, format) {
25+
if (format === 'cjs') {
26+
outputOpts.footer = (chunk) => {
27+
// don't append to dts files
28+
if (chunk.fileName.endsWith('.cjs')) {
29+
return 'module.exports.default = module.exports'
30+
}
31+
return ''
32+
}
33+
}
34+
return outputOpts
35+
},
36+
onSuccess() {
37+
writeFileSync(
38+
'dist/package.json',
39+
JSON.stringify(
40+
{
41+
...Object.fromEntries(
42+
Object.entries(packageJSON).filter(
43+
([key, _val]) =>
44+
key !== 'devDependencies' &&
45+
key !== 'scripts' &&
46+
key !== 'private',
47+
),
48+
),
49+
main: 'index.cjs',
50+
types: 'index.d.ts',
51+
module: 'index.js',
52+
exports: {
53+
'.': {
54+
require: './index.cjs',
55+
import: './index.js',
56+
},
57+
},
58+
},
59+
null,
60+
2,
61+
),
62+
)
63+
},
64+
})

pnpm-lock.yaml

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)