bunchee 6.0.3 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -28
- package/dist/bin/cli.js +1 -1
- package/dist/index.js +1 -3
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -22,28 +22,45 @@ It uses the standard exports configuration in `package.json` as the only source
|
|
|
22
22
|
### Installation
|
|
23
23
|
|
|
24
24
|
```sh
|
|
25
|
-
npm install --save-dev bunchee
|
|
25
|
+
npm install --save-dev bunchee typescript
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### Configuration
|
|
29
|
+
|
|
30
|
+
Create entry files of your library and `package.json`.
|
|
29
31
|
|
|
30
32
|
```sh
|
|
31
|
-
|
|
33
|
+
cd ./coffee
|
|
34
|
+
mkdir src && touch ./src/index.ts && touch package.json
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
Add the exports in `package.json`.
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"name": "coffee",
|
|
42
|
+
"type": "module",
|
|
43
|
+
"main": "./dist/index.js",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "bunchee"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Build
|
|
37
51
|
|
|
38
52
|
```sh
|
|
39
|
-
|
|
40
|
-
mkdir src && touch ./src/index.ts
|
|
53
|
+
npm run build
|
|
41
54
|
```
|
|
42
55
|
|
|
43
|
-
|
|
56
|
+
Then files in `src` folders will be treated as entry files and match the export names in package.json.
|
|
57
|
+
Simply like Node.js module resolution, each export name will match the file in `src/` directory.
|
|
58
|
+
|
|
59
|
+
For example:
|
|
44
60
|
|
|
45
|
-
|
|
46
|
-
`src/
|
|
61
|
+
- `src/index.ts` will match the exports name `"."` or the only main export.
|
|
62
|
+
- `src/lite.ts` will match the exports name `"./lite"`.
|
|
63
|
+
- `src/react/index.ts` will match the exports name `"./react"`.
|
|
47
64
|
|
|
48
65
|
Now just run `npm run build` (or `pnpm build` / `yarn build`) if you're using these package managers, `bunchee` will find the entry files and build them.
|
|
49
66
|
The output format will based on the exports condition and also the file extension. Given an example:
|
|
@@ -69,16 +86,17 @@ npm exec bunchee prepare
|
|
|
69
86
|
Or you can checkout the following cases to configure your package.json.
|
|
70
87
|
|
|
71
88
|
<details>
|
|
72
|
-
<summary>
|
|
89
|
+
<summary>JavaScript ESModule</summary>
|
|
73
90
|
|
|
74
91
|
Then use use the [exports field in package.json](https://nodejs.org/api/packages.html#exports-sugar) to configure different conditions and leverage the same functionality as other bundlers, such as webpack. The exports field allows you to define multiple conditions.
|
|
75
92
|
|
|
76
93
|
```json
|
|
77
94
|
{
|
|
78
95
|
"files": ["dist"],
|
|
96
|
+
"type": "module",
|
|
79
97
|
"exports": {
|
|
80
|
-
"
|
|
81
|
-
"
|
|
98
|
+
".": "./dist/es/index.js",
|
|
99
|
+
"./react": "./dist/es/react.js"
|
|
82
100
|
},
|
|
83
101
|
"scripts": {
|
|
84
102
|
"build": "bunchee"
|
|
@@ -91,19 +109,21 @@ Then use use the [exports field in package.json](https://nodejs.org/api/packages
|
|
|
91
109
|
<details>
|
|
92
110
|
<summary>TypeScript</summary>
|
|
93
111
|
|
|
94
|
-
If you're build a TypeScript library, separate the types from the main entry file and specify the types path in package.json.
|
|
112
|
+
If you're build a TypeScript library, separate the types from the main entry file and specify the types path in package.json. Types exports need to stay on the top of each export with `types` condition, and you can use `default` condition for the JS bundle file.
|
|
95
113
|
|
|
96
114
|
```json
|
|
97
115
|
{
|
|
98
116
|
"files": ["dist"],
|
|
117
|
+
"type": "module",
|
|
118
|
+
"main": "./dist/index.js",
|
|
99
119
|
"exports": {
|
|
100
|
-
"
|
|
101
|
-
"types": "./dist/
|
|
102
|
-
"default": "./dist/
|
|
120
|
+
".": {
|
|
121
|
+
"types": "./dist/index.d.ts",
|
|
122
|
+
"default": "./dist/index.js"
|
|
103
123
|
},
|
|
104
|
-
"
|
|
105
|
-
"types": "./dist/
|
|
106
|
-
"default": "./dist/
|
|
124
|
+
"./react": {
|
|
125
|
+
"types": "./dist/react/index.d.ts",
|
|
126
|
+
"default": "./dist/react/index.js"
|
|
107
127
|
}
|
|
108
128
|
},
|
|
109
129
|
"scripts": {
|
|
@@ -118,20 +138,23 @@ If you're build a TypeScript library, separate the types from the main entry fil
|
|
|
118
138
|
<summary>Hybrid (CJS & ESM) Module Resolution with TypeScript</summary>
|
|
119
139
|
If you're using TypeScript with Node 10 and Node 16 module resolution, you can use the `types` field in package.json to specify the types path. Then `bunchee` will generate the types file with the same extension as the main entry file.
|
|
120
140
|
|
|
141
|
+
_NOTE_: When you're using `.mjs` or `.cjs` extensions with TypeScript and modern module resolution (above node16), TypeScript will require specific type declaration files like `.d.mts` or `.d.cts` to match the extension. `bunchee` can automatically generate them to match the types to match the condition and extensions.
|
|
142
|
+
|
|
121
143
|
```json
|
|
122
144
|
{
|
|
123
145
|
"files": ["dist"],
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
146
|
+
"type": "module",
|
|
147
|
+
"main": "./dist/index.js",
|
|
148
|
+
"module": "./dist/index.js",
|
|
149
|
+
"types": "./dist/index.d.ts",
|
|
127
150
|
"exports": {
|
|
128
151
|
"import": {
|
|
129
|
-
"types": "./dist/
|
|
130
|
-
"default": "./dist/
|
|
152
|
+
"types": "./dist/index.d.ts",
|
|
153
|
+
"default": "./dist/index.js"
|
|
131
154
|
},
|
|
132
155
|
"require": {
|
|
133
|
-
"types": "./dist/
|
|
134
|
-
"default": "./dist/
|
|
156
|
+
"types": "./dist/index.d.cts",
|
|
157
|
+
"default": "./dist/index.cjs"
|
|
135
158
|
}
|
|
136
159
|
},
|
|
137
160
|
"scripts": {
|
|
@@ -176,10 +199,11 @@ Assuming you have default export package as `"."` and subpath export `"./lite"`
|
|
|
176
199
|
"scripts": {
|
|
177
200
|
"build": "bunchee"
|
|
178
201
|
},
|
|
202
|
+
"type": "module",
|
|
179
203
|
"exports": {
|
|
180
204
|
"./lite": "./dist/lite.js",
|
|
181
205
|
".": {
|
|
182
|
-
"import": "./dist/index.
|
|
206
|
+
"import": "./dist/index.js",
|
|
183
207
|
"require": "./dist/index.cjs"
|
|
184
208
|
}
|
|
185
209
|
}
|
package/dist/bin/cli.js
CHANGED
|
@@ -612,7 +612,7 @@ function lint$1(pkg) {
|
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
-
var version = "6.0.
|
|
615
|
+
var version = "6.0.4";
|
|
616
616
|
|
|
617
617
|
async function writeDefaultTsconfig(tsConfigPath) {
|
|
618
618
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
package/dist/index.js
CHANGED
|
@@ -1526,9 +1526,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1526
1526
|
return externals.some((name)=>id === name || id.startsWith(name + '/'));
|
|
1527
1527
|
},
|
|
1528
1528
|
plugins,
|
|
1529
|
-
treeshake:
|
|
1530
|
-
propertyReadSideEffects: false
|
|
1531
|
-
},
|
|
1529
|
+
treeshake: 'recommended',
|
|
1532
1530
|
onwarn (warning, warn) {
|
|
1533
1531
|
const code = warning.code || '';
|
|
1534
1532
|
// Some may not have types, like CLI binary
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -77,15 +77,18 @@
|
|
|
77
77
|
"@types/jest": "29.0.0",
|
|
78
78
|
"@types/node": "^22.9.3",
|
|
79
79
|
"@types/picomatch": "^3.0.1",
|
|
80
|
+
"@types/react": "19.0.1",
|
|
80
81
|
"@types/yargs": "^17.0.33",
|
|
81
82
|
"bunchee": "link:./",
|
|
82
83
|
"cross-env": "^7.0.3",
|
|
83
84
|
"husky": "^9.0.11",
|
|
84
85
|
"jest": "29.0.1",
|
|
85
86
|
"lint-staged": "^15.2.2",
|
|
87
|
+
"next": "^15.0.4",
|
|
86
88
|
"picocolors": "^1.0.0",
|
|
87
89
|
"prettier": "^3.0.0",
|
|
88
|
-
"react": "^
|
|
90
|
+
"react": "^19.0.0",
|
|
91
|
+
"react-dom": "^19.0.0",
|
|
89
92
|
"typescript": "^5.6.2"
|
|
90
93
|
},
|
|
91
94
|
"lint-staged": {
|
|
@@ -114,6 +117,8 @@
|
|
|
114
117
|
"test:ci": "pnpm test -- --ci",
|
|
115
118
|
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|
|
116
119
|
"test:post": "cross-env POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
|
|
120
|
+
"docs:dev": "next dev docs",
|
|
121
|
+
"docs:build": "next build docs",
|
|
117
122
|
"clean": "rm -rf ./dist",
|
|
118
123
|
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
|
|
119
124
|
"prepare-release": "pnpm clean && pnpm build",
|