Skip to content

Commit 1d82511

Browse files
committed
build(tsdown): migrate from tsc to tsdown for CJS/ESM dual output
Replaces tsc with tsdown to produce proper ESM output and resolve Vite's CJS interop double-wrap issue. Adds exports field with import/ require conditions pointing to dist/index.mjs and dist/index.cjs.
1 parent ec42db6 commit 1d82511

8 files changed

Lines changed: 558 additions & 131 deletions

File tree

.cspell.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,5 @@
1414
"subdir",
1515
"testattribute"
1616
],
17-
"ignorePaths": [
18-
"coverage",
19-
"dist",
20-
"lib",
21-
"node_modules",
22-
"package.json",
23-
"package-lock.json",
24-
"src/dom/attributes/*.ts"
25-
]
17+
"ignorePaths": ["coverage", "dist", "node_modules", "package.json", "package-lock.json", "src/dom/attributes/*.ts"]
2618
}

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
.cspell.json
33
biome.json
44
tsconfig.json
5-
tsconfig.*.json
5+
tsdown.config.ts
66
node_modules
77
/coverage/
88
/test/
99
/demo/
10+
/lib/
11+
/src/
1012
vite.*.ts
1113
vitest.config.ts

package-lock.json

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

package.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22
"name": "@orrisroot/react-html-parser",
33
"version": "3.0.0",
44
"description": "Parse HTML into React components",
5-
"main": "lib/index.js",
6-
"types": "lib/index.d.ts",
5+
"main": "dist/index.cjs",
6+
"module": "dist/index.mjs",
7+
"types": "dist/index.d.cts",
8+
"exports": {
9+
"import": {
10+
"types": "./dist/index.d.mts",
11+
"default": "./dist/index.mjs"
12+
},
13+
"require": {
14+
"types": "./dist/index.d.cts",
15+
"default": "./dist/index.cjs"
16+
}
17+
},
718
"umd:main": "dist/react-html-parser.min.js",
819
"unpkg": "dist/react-html-parser.min.js",
920
"jsdelivr": "dist/react-html-parser.min.js",
1021
"source": "src/index.ts",
1122
"scripts": {
12-
"clean": "rimraf coverage dist lib",
23+
"clean": "rimraf coverage dist",
1324
"check": "npm run lint && npm run test",
1425
"test": "vitest run",
1526
"test:watch": "vitest",
@@ -18,7 +29,7 @@
1829
"lint:fix": "biome check --write .",
1930
"format": "biome format --write .",
2031
"build": "npm run build:lib && npm run build:umd:min && npm run build:umd",
21-
"build:lib": "rimraf lib && tsc -p tsconfig.lib.json && tsc -p tsconfig.types.json",
32+
"build:lib": "tsdown",
2233
"build:umd": "vite build --config vite.dev.ts",
2334
"build:umd:min": "vite build --config vite.prod.ts",
2435
"prerelease": "npm run clean && npm run check",
@@ -60,9 +71,10 @@
6071
"react": "^19.2.6",
6172
"react-dom": "^19.2.6",
6273
"rimraf": "^6.1.3",
63-
"terser": "^5.47.1",
74+
"terser": "^5.48.0",
75+
"tsdown": "^0.22.0",
6476
"typescript": "^6.0.3",
65-
"vite": "^8.0.13",
77+
"vite": "^8.0.14",
6678
"vitest": "^4.1.7"
6779
},
6880
"dependencies": {

tsconfig.lib.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

tsconfig.types.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

tsdown.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'tsdown';
2+
3+
export default defineConfig({
4+
entry: ['src/index.ts'],
5+
format: ['cjs', 'esm'],
6+
dts: true,
7+
sourcemap: true,
8+
clean: false,
9+
target: 'es2019',
10+
outDir: 'dist',
11+
deps: {
12+
neverBundle: ['react', 'htmlparser2'],
13+
},
14+
});

vite.prod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineConfig } from 'vite';
33

44
export default defineConfig({
55
build: {
6+
emptyOutDir: false,
67
lib: {
78
entry: path.resolve(__dirname, 'src/index.ts'),
89
name: 'ReactHtmlParser',

0 commit comments

Comments
 (0)