bunchee 2.0.0-beta.5 → 2.0.2
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 +62 -11
- package/dist/cli.js +1 -1
- package/dist/lib.js +39 -23
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ Leverage `exports` field to support different conditions would be also ideal. Mo
|
|
|
54
54
|
"exports": {
|
|
55
55
|
"require": "dist/index.cjs",
|
|
56
56
|
"import": "dist/index.mjs",
|
|
57
|
-
"module": "dist/index.esm.js"
|
|
57
|
+
"module": "dist/index.esm.js"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "bunchee ./src/index.js"
|
|
@@ -85,15 +85,7 @@ Usage:
|
|
|
85
85
|
$ bunchee ./src/index.ts -o ./dist/bundle.js # specify the dist file path
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
```js
|
|
91
|
-
import { bundle } from 'bunchee'
|
|
92
|
-
|
|
93
|
-
// options is same to CLI options
|
|
94
|
-
await bundle(entryFilePath, options)
|
|
95
|
-
```
|
|
96
|
-
#### Example Scripts
|
|
88
|
+
Run bunchee via CLI
|
|
97
89
|
|
|
98
90
|
```sh
|
|
99
91
|
cd <project-root-dir>
|
|
@@ -104,7 +96,16 @@ bunchee ./src/index.js -f esm -o ./dist/bundle.esm.js
|
|
|
104
96
|
# bunchee ./src/index.js -o ./dist/bundle.esm.js
|
|
105
97
|
```
|
|
106
98
|
|
|
107
|
-
###
|
|
99
|
+
### Node.js API
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { bundle } from 'bunchee'
|
|
103
|
+
|
|
104
|
+
// options is same to CLI options
|
|
105
|
+
await bundle(entryFilePath, options)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Typescript
|
|
108
109
|
|
|
109
110
|
By default bunchee includes Typescript v3.9.x inside as a dependency. If you want to use your own version, just install typescript as another dev dependency then bunchee will automatically pick it.
|
|
110
111
|
|
|
@@ -112,4 +113,54 @@ By default bunchee includes Typescript v3.9.x inside as a dependency. If you wan
|
|
|
112
113
|
yarn add -D bunchee typescript
|
|
113
114
|
```
|
|
114
115
|
|
|
116
|
+
Create `tsconfig.json` to specify any compiler options for TypeScript.
|
|
117
|
+
|
|
115
118
|
This library requires at least [TypeScript 3.7](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html).
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Advanced
|
|
122
|
+
|
|
123
|
+
### Multiple Exports
|
|
124
|
+
|
|
125
|
+
While `exports` filed is becoming the standard of exporting in node.js, bunchee also supports to build multiple exports all in one command.
|
|
126
|
+
|
|
127
|
+
What you need to do is just add an entry file with the name (`[name].[ext]`) that matches the exported name from exports field in package.json. For instance:
|
|
128
|
+
|
|
129
|
+
* `index.ts` will match `"."` export name or the if there's only one main export.
|
|
130
|
+
* `lite.ts` will match `"./lite"` export name.
|
|
131
|
+
|
|
132
|
+
The build script will be simplified to just `bunchee` in package.json without configure any input sources for each exports. Of course you can still specify other arguments as you need.
|
|
133
|
+
|
|
134
|
+
#### How it works
|
|
135
|
+
|
|
136
|
+
Assuming you have main entry export `"."` and subpath export `"./lite"` with different exports condition listed in package.json
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"name": "example",
|
|
141
|
+
"scripts": {
|
|
142
|
+
"build": "bunchee"
|
|
143
|
+
},
|
|
144
|
+
"exports": {
|
|
145
|
+
"./lite": "./dist/lite.js"
|
|
146
|
+
".": {
|
|
147
|
+
"import": "./dist/index.mjs",
|
|
148
|
+
"require": "./dist/index.cjs"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Then you need to add two entry files `index.ts` and `lite.ts` in project root directory to match the export name `"."` and `"./lite"`, bunchee will associate these entry files with export names then use them as input source and output paths information.
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
- example/
|
|
158
|
+
|- lite.ts
|
|
159
|
+
|- index.ts
|
|
160
|
+
|- src/
|
|
161
|
+
|- package.json
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### License
|
|
165
|
+
|
|
166
|
+
MIT
|
package/dist/cli.js
CHANGED
|
@@ -87,7 +87,7 @@ var logger = {
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
var version = "2.0.
|
|
90
|
+
var version = "2.0.2";
|
|
91
91
|
|
|
92
92
|
var helpMessage = '\nUsage: bunchee [options]\n\nOptions:\n -v, --version output the version number\n -w, --watch watch src files changes\n -m, --minify compress output. false by default\n -o, --output <file> specify output filename\n -f, --format <format> specify bundle type: "esm", "cjs", "umd". "esm" by default\n -e, --external <mod> specify an external dependency\n --target <target> js features target: swc target es versions. "es5" by default\n --runtime <runtime> build runtime: "nodejs", "browser". "browser" by default\n --sourcemap enable sourcemap generation, false by default\n --cwd <cwd> specify current working directory\n -h, --help output usage information\n';
|
|
93
93
|
function help() {
|
package/dist/lib.js
CHANGED
|
@@ -96,9 +96,10 @@ function resolveTypescript() {
|
|
|
96
96
|
function getDistPath(distPath) {
|
|
97
97
|
return path.resolve(config.rootDir, distPath);
|
|
98
98
|
}
|
|
99
|
-
function createInputConfig(entry, pkg, options) {
|
|
100
|
-
var _a;
|
|
99
|
+
function createInputConfig(entry, pkg, options, _a) {
|
|
101
100
|
var _b;
|
|
101
|
+
var _c;
|
|
102
|
+
var tsCompilerOptions = _a.tsCompilerOptions;
|
|
102
103
|
var externals = [
|
|
103
104
|
pkg.peerDependencies,
|
|
104
105
|
pkg.dependencies,
|
|
@@ -109,7 +110,7 @@ function createInputConfig(entry, pkg, options) {
|
|
|
109
110
|
return Object.keys(o);
|
|
110
111
|
}).reduce(function(a, b) {
|
|
111
112
|
return a.concat(b);
|
|
112
|
-
}, []).concat(((
|
|
113
|
+
}, []).concat(((_c = options.external) !== null && _c !== void 0 ? _c : []).concat(pkg.name ? [
|
|
113
114
|
pkg.name
|
|
114
115
|
] : []));
|
|
115
116
|
var useTypescript = options.useTypescript, runtime = options.runtime, jscTarget = options.target, minify = options.minify, exportCondition = options.exportCondition;
|
|
@@ -148,9 +149,9 @@ function createInputConfig(entry, pkg, options) {
|
|
|
148
149
|
useTypescript && isMainExport && require("@rollup/plugin-typescript")(tslib.__assign({
|
|
149
150
|
tsconfig: tsPath,
|
|
150
151
|
typescript: resolveTypescript(),
|
|
151
|
-
jsx: "react",
|
|
152
|
+
jsx: (tsCompilerOptions === null || tsCompilerOptions === void 0 ? void 0 : tsCompilerOptions.jsx) || "react",
|
|
152
153
|
module: "ES6",
|
|
153
|
-
target:
|
|
154
|
+
target: jscTarget,
|
|
154
155
|
noEmitOnError: !options.watch,
|
|
155
156
|
sourceMap: options.sourcemap,
|
|
156
157
|
declaration: !!typings,
|
|
@@ -166,9 +167,17 @@ function createInputConfig(entry, pkg, options) {
|
|
|
166
167
|
target: jscTarget,
|
|
167
168
|
loose: true,
|
|
168
169
|
externalHelpers: false,
|
|
169
|
-
parser: (
|
|
170
|
+
parser: (_b = {
|
|
170
171
|
syntax: useTypescript ? "typescript" : "ecmascript"
|
|
171
|
-
},
|
|
172
|
+
}, _b[useTypescript ? "tsx" : "jsx"] = true, _b.privateMethod = true, _b.classPrivateProperty = true, _b.exportDefaultFrom = true, _b),
|
|
173
|
+
transform: {
|
|
174
|
+
react: {
|
|
175
|
+
runtime: [
|
|
176
|
+
"react-jsx",
|
|
177
|
+
"react-jsx-dev"
|
|
178
|
+
].includes(tsCompilerOptions === null || tsCompilerOptions === void 0 ? void 0 : tsCompilerOptions.jsx) ? "automatic" : "classic"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
172
181
|
}, minify && {
|
|
173
182
|
minify: tslib.__assign(tslib.__assign({}, minifyOptions), {
|
|
174
183
|
sourceMap: options.sourcemap
|
|
@@ -205,17 +214,9 @@ function createInputConfig(entry, pkg, options) {
|
|
|
205
214
|
}
|
|
206
215
|
};
|
|
207
216
|
}
|
|
208
|
-
function createOutputOptions(options, pkg) {
|
|
209
|
-
var
|
|
210
|
-
var
|
|
211
|
-
if (useTypescript) {
|
|
212
|
-
var ts = resolveTypescript();
|
|
213
|
-
var tsconfigPath = path.resolve(config.rootDir, "tsconfig.json");
|
|
214
|
-
if (fs__default["default"].existsSync(tsconfigPath)) {
|
|
215
|
-
var tsconfigJSON = ts.readConfigFile(tsconfigPath, ts.sys.readFile).config;
|
|
216
|
-
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, "./").options;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
217
|
+
function createOutputOptions(options, pkg, _a) {
|
|
218
|
+
var tsCompilerOptions = _a.tsCompilerOptions;
|
|
219
|
+
var format = options.format;
|
|
219
220
|
var exportPaths = getExportPaths(pkg);
|
|
220
221
|
var useEsModuleMark = Boolean(tsCompilerOptions.esModuleInterop || exportPaths.main && exportPaths.module);
|
|
221
222
|
var file = path.resolve(options.file);
|
|
@@ -345,14 +346,27 @@ function createRollupConfig(entry, pkg, cliArgs) {
|
|
|
345
346
|
var options = tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
346
347
|
useTypescript: useTypescript
|
|
347
348
|
});
|
|
348
|
-
var
|
|
349
|
+
var tsCompilerOptions = {};
|
|
350
|
+
if (useTypescript) {
|
|
351
|
+
var ts = resolveTypescript();
|
|
352
|
+
var tsconfigPath = path.resolve(config.rootDir, "tsconfig.json");
|
|
353
|
+
if (fs__default["default"].existsSync(tsconfigPath)) {
|
|
354
|
+
var tsconfigJSON = ts.readConfigFile(tsconfigPath, ts.sys.readFile).config;
|
|
355
|
+
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, "./").options;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
var inputOptions = createInputConfig(entry, pkg, options, {
|
|
359
|
+
tsCompilerOptions: tsCompilerOptions
|
|
360
|
+
});
|
|
349
361
|
var outputExports = options.exportCondition ? getSubExportDist(pkg, options.exportCondition.export) : getExportDist(pkg);
|
|
350
362
|
var outputConfigs = outputExports.map(function(exportDist) {
|
|
351
363
|
return createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
352
364
|
file: exportDist.file,
|
|
353
365
|
format: exportDist.format,
|
|
354
366
|
useTypescript: useTypescript
|
|
355
|
-
}), pkg
|
|
367
|
+
}), pkg, {
|
|
368
|
+
tsCompilerOptions: tsCompilerOptions
|
|
369
|
+
});
|
|
356
370
|
});
|
|
357
371
|
if (file) {
|
|
358
372
|
var format = (_a = outputExports[0]) === null || _a === void 0 ? void 0 : _a.format;
|
|
@@ -361,13 +375,15 @@ function createRollupConfig(entry, pkg, cliArgs) {
|
|
|
361
375
|
file: file,
|
|
362
376
|
format: format || cliArgs.format,
|
|
363
377
|
useTypescript: useTypescript
|
|
364
|
-
}), pkg
|
|
378
|
+
}), pkg, {
|
|
379
|
+
tsCompilerOptions: tsCompilerOptions
|
|
380
|
+
}),
|
|
365
381
|
];
|
|
366
382
|
}
|
|
367
383
|
return {
|
|
368
384
|
input: inputOptions,
|
|
369
385
|
output: outputConfigs,
|
|
370
|
-
exportName: ((_b = options.exportCondition) === null || _b === void 0 ? void 0 : _b.name) ||
|
|
386
|
+
exportName: ((_b = options.exportCondition) === null || _b === void 0 ? void 0 : _b.name) || "."
|
|
371
387
|
};
|
|
372
388
|
}
|
|
373
389
|
|
|
@@ -453,7 +469,7 @@ function bundle(entryPath, _a) {
|
|
|
453
469
|
return bundleOrWatch(rollupConfig);
|
|
454
470
|
}
|
|
455
471
|
function getExportPath(pkg, exportName) {
|
|
456
|
-
var name = pkg.name ||
|
|
472
|
+
var name = pkg.name || path.basename(config.rootDir);
|
|
457
473
|
if (exportName === "." || !exportName) return name;
|
|
458
474
|
return path.join(name, exportName);
|
|
459
475
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bunchee": "./dist/cli.js"
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"jest": "29.0.1",
|
|
58
|
+
"react": "18.2.0",
|
|
58
59
|
"tsx": "3.4.3",
|
|
59
60
|
"typescript": "4.8.2"
|
|
60
61
|
},
|