bunchee 4.3.3 → 4.4.0
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 +31 -11
- package/dist/bin/cli.js +394 -34
- package/dist/index.d.ts +1 -0
- package/dist/index.js +281 -238
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ npm install --save-dev bunchee typescript
|
|
|
34
34
|
### Configuration
|
|
35
35
|
|
|
36
36
|
Create your library entry file and package.json.
|
|
37
|
+
|
|
37
38
|
```sh
|
|
38
39
|
cd ./my-lib
|
|
39
40
|
mkdir src && touch ./src/index.ts
|
|
@@ -57,18 +58,20 @@ Or you can checkout the following cases to configure your package.json.
|
|
|
57
58
|
<summary> JavaScript</summary>
|
|
58
59
|
|
|
59
60
|
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.
|
|
61
|
+
|
|
60
62
|
```json
|
|
61
63
|
{
|
|
62
64
|
"files": ["dist"],
|
|
63
65
|
"exports": {
|
|
64
66
|
"import": "./dist/es/index.mjs",
|
|
65
|
-
"require": "./dist/cjs/index.
|
|
67
|
+
"require": "./dist/cjs/index.js"
|
|
66
68
|
},
|
|
67
69
|
"scripts": {
|
|
68
70
|
"build": "bunchee"
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
```
|
|
74
|
+
|
|
72
75
|
</details>
|
|
73
76
|
|
|
74
77
|
<details>
|
|
@@ -85,8 +88,8 @@ If you're build a TypeScript library, separate the types from the main entry fil
|
|
|
85
88
|
"default": "./dist/es/index.mjs"
|
|
86
89
|
},
|
|
87
90
|
"require": {
|
|
88
|
-
"types": "./dist/cjs/index.d.
|
|
89
|
-
"default": "./dist/cjs/index.
|
|
91
|
+
"types": "./dist/cjs/index.d.ts",
|
|
92
|
+
"default": "./dist/cjs/index.js"
|
|
90
93
|
}
|
|
91
94
|
},
|
|
92
95
|
"scripts": {
|
|
@@ -94,8 +97,8 @@ If you're build a TypeScript library, separate the types from the main entry fil
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
```
|
|
97
|
-
</details>
|
|
98
100
|
|
|
101
|
+
</details>
|
|
99
102
|
|
|
100
103
|
<details>
|
|
101
104
|
<summary>Hybrid (CJS & ESM) Module Resolution with TypeScript</summary>
|
|
@@ -104,13 +107,13 @@ If you're using TypeScript with Node 10 and Node 16 module resolution, you can u
|
|
|
104
107
|
```json
|
|
105
108
|
{
|
|
106
109
|
"files": ["dist"],
|
|
107
|
-
"main": "./dist/cjs/index.
|
|
110
|
+
"main": "./dist/cjs/index.js",
|
|
108
111
|
"module": "./dist/es/index.mjs",
|
|
109
112
|
"types": "./dist/cjs/index.d.ts",
|
|
110
113
|
"exports": {
|
|
111
114
|
"import": {
|
|
112
|
-
"types": "./dist/es/index.d.
|
|
113
|
-
"default": "./dist/es/index.
|
|
115
|
+
"types": "./dist/es/index.d.ts",
|
|
116
|
+
"default": "./dist/es/index.js"
|
|
114
117
|
},
|
|
115
118
|
"require": {
|
|
116
119
|
"types": "./dist/cjs/index.d.cts",
|
|
@@ -122,6 +125,7 @@ If you're using TypeScript with Node 10 and Node 16 module resolution, you can u
|
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
```
|
|
128
|
+
|
|
125
129
|
</details>
|
|
126
130
|
|
|
127
131
|
#### Build
|
|
@@ -240,7 +244,6 @@ This will match the `bin` field in package.json as:
|
|
|
240
244
|
|
|
241
245
|
> Note: For multiple `bin` files, the filename should match the key name in the `bin` field.
|
|
242
246
|
|
|
243
|
-
|
|
244
247
|
### Server Components
|
|
245
248
|
|
|
246
249
|
`bunchee` supports to build server components and server actions with library directives like `"use client"` or `"use server"`. It will generate the corresponding chunks for client and server that scope the client and server boundaries properly.
|
|
@@ -265,6 +268,7 @@ If you're using `"use client"` or `"use server"` in a file that used as a depend
|
|
|
265
268
|
- Types (`--dts`): Generate TypeScript declaration files along with assets.
|
|
266
269
|
- Minify (`-m`): Compress output.
|
|
267
270
|
- Watch (`-w`): Watch for source file changes.
|
|
271
|
+
- No Clean(`--no-clean`): Do not clean the dist folder before building. (default: `false`)
|
|
268
272
|
|
|
269
273
|
```sh
|
|
270
274
|
cd <project-root-dir>
|
|
@@ -280,7 +284,7 @@ bunchee ./src/index.js --runtime node --target es2019
|
|
|
280
284
|
|
|
281
285
|
#### Specifying extra external dependencies
|
|
282
286
|
|
|
283
|
-
By default, `bunchee` will mark all the `dependencies` and `peerDependencies` as externals so you don't need to pass them as CLI args.
|
|
287
|
+
By default, `bunchee` will mark all the `dependencies` and `peerDependencies` as externals so you don't need to pass them as CLI args.
|
|
284
288
|
But if there's any dependency that used but not in the dependency list and you want to mark as external, you can use the `--external` option to specify them.
|
|
285
289
|
|
|
286
290
|
```sh
|
|
@@ -309,7 +313,6 @@ bunchee --env=ENV1,ENV2,ENV3
|
|
|
309
313
|
|
|
310
314
|
Replace `ENV1`, `ENV2`, and `ENV3` with the names of the environment variables you want to include in your bundled code. These environment variables will be inlined during the bundling process.
|
|
311
315
|
|
|
312
|
-
|
|
313
316
|
You can use `index.<export-type>.<ext>` to override the input source file for specific export name. Or using `<export-path>/index.<export-type>.<ext>` also works. Such as:
|
|
314
317
|
|
|
315
318
|
```
|
|
@@ -321,6 +324,20 @@ You can use `index.<export-type>.<ext>` to override the input source file for sp
|
|
|
321
324
|
|
|
322
325
|
This will match the export name `"react-server"` and `"edge-light"` then use the corresponding input source file to build the bundle.
|
|
323
326
|
|
|
327
|
+
#### Auto Development and Production Mode
|
|
328
|
+
|
|
329
|
+
`process.env.NODE_ENV` is injected by default if present that you don't need to manually inject yourself. If you need to separate the development build and production build, `bunchee` provides different export conditions for development and production mode with `development` and `production` export conditions.
|
|
330
|
+
|
|
331
|
+
```json
|
|
332
|
+
{
|
|
333
|
+
"exports": {
|
|
334
|
+
"development": "./dist/index.development.js",
|
|
335
|
+
"production": "./dist/index.production.js"
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Then you can use `bunchee` to build the development bundle and production bundle automatically.
|
|
324
341
|
|
|
325
342
|
### Wildcard Exports
|
|
326
343
|
|
|
@@ -402,6 +419,7 @@ If you just want to import a file as string content, you can name the extension
|
|
|
402
419
|
For example:
|
|
403
420
|
|
|
404
421
|
src/index.ts
|
|
422
|
+
|
|
405
423
|
```js
|
|
406
424
|
import data from './data.txt'
|
|
407
425
|
|
|
@@ -409,11 +427,13 @@ export default data
|
|
|
409
427
|
```
|
|
410
428
|
|
|
411
429
|
src/data.txt
|
|
430
|
+
|
|
412
431
|
```txt
|
|
413
432
|
hello world
|
|
414
433
|
```
|
|
415
434
|
|
|
416
435
|
output
|
|
436
|
+
|
|
417
437
|
```
|
|
418
438
|
export default "hello world"
|
|
419
439
|
```
|
|
@@ -435,6 +455,7 @@ await bundle(path.resolve('./src/index.ts'), {
|
|
|
435
455
|
target: 'es2015', // ES syntax target
|
|
436
456
|
runtime: 'nodejs', // 'browser' | 'nodejs'
|
|
437
457
|
cwd: process.cwd(), // string
|
|
458
|
+
clean: true, // boolean
|
|
438
459
|
})
|
|
439
460
|
```
|
|
440
461
|
|
|
@@ -450,7 +471,6 @@ If you specify `target` option in `tsconfig.json`, then you don't have to pass i
|
|
|
450
471
|
|
|
451
472
|
`bunchee` has support for checking the package bundles are matched with package exports configuration.
|
|
452
473
|
|
|
453
|
-
|
|
454
474
|
### License
|
|
455
475
|
|
|
456
476
|
MIT
|