quickbundle 2.3.0 → 2.4.1
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 +17 -13
- package/dist/index.js +53 -21
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,13 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
Quickbundle allows you to bundle a library in a **quick**, **fast** and **easy** way:
|
|
12
12
|
|
|
13
|
-
- Fast build and watch mode powered by [
|
|
13
|
+
- Fast build and watch mode powered by Rollup[^1] and SWC[^2].
|
|
14
14
|
- Zero configuration: define the build artifacts in your `package.json`, and you're all set!
|
|
15
15
|
- Support of `cjs` & `esm` module formats output.
|
|
16
16
|
- Support of several loaders including JavaScript, TypeScript, JSX, JSON, and Images.
|
|
17
17
|
- TypeScript's declaration file (`.d.ts`) bundling.
|
|
18
18
|
- Automatic dependency inclusion (`peerDependencies` and `dependencies` are not bundled in the final output, `devDependencies` are unless they're not imported).
|
|
19
19
|
|
|
20
|
+
[^1]: A [module bundler](https://rollupjs.org/) optimized for better tree-shaking processing and seamless interoperability of CommonJS and ESM formats with minimal code footprint.
|
|
21
|
+
|
|
22
|
+
[^2]: A [TypeScript / JavaScript transpiler](https://swc.rs/) for quicker code processing including TypeScript transpilation, JavaScript transformation, and, minification.
|
|
23
|
+
|
|
20
24
|
<br>
|
|
21
25
|
|
|
22
26
|
## 🚀 Quick Start
|
|
@@ -34,20 +38,18 @@ yarn add quickbundle
|
|
|
34
38
|
|
|
35
39
|
2️⃣ Set up your package configuration (`package.json`):
|
|
36
40
|
|
|
37
|
-
- When exporting
|
|
41
|
+
- When exporting exclusively ESM format:
|
|
38
42
|
|
|
39
43
|
```jsonc
|
|
40
44
|
{
|
|
41
45
|
"name": "lib", // Package name
|
|
42
46
|
"exports": {
|
|
43
47
|
".": {
|
|
44
|
-
"source": "src/index.ts(x)?", // Source code
|
|
45
|
-
"types": "./dist/index.d.ts", // Typing output file (if defined, can increase build time)
|
|
46
|
-
"
|
|
47
|
-
"require": "./dist/index.cjs", // CommonJS output file (matches when the module is loaded via require() consumer side)
|
|
48
|
-
"default": "./dist/index.mjs", // The generic fallback that always matches (this condition should always come last). By default, Quickbundle will always output ESM format for the `default` field. However, take care: if both `import` and `default` fields are defined, provide the same file path, as the `import` field export instruction will be the only one considered to define the output file path.
|
|
48
|
+
"source": "src/index.ts(x)?", // Source code entry point.
|
|
49
|
+
"types": "./dist/index.d.ts", // Typing output file (if defined, can increase build time). This condition should always come first after the custom `source` field definition.
|
|
50
|
+
"default": "./dist/index.mjs", // By default, Quickbundle will always output ESM format for the `default` field (this condition should always come last since it always matches as a generic fallback). However, take care: if both `import` and `default` fields are defined, provide the same file path, as the `import` field export instruction will be the only one considered to define the output file path.
|
|
49
51
|
},
|
|
50
|
-
"./
|
|
52
|
+
"./otherModulePath": {
|
|
51
53
|
// ...
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -59,18 +61,20 @@ yarn add quickbundle
|
|
|
59
61
|
}
|
|
60
62
|
```
|
|
61
63
|
|
|
62
|
-
- When exporting
|
|
64
|
+
- When exporting both CommonJS (CJS) and ECMAScript Modules (ESM) format (please be aware of [dual package hazard risk](https://nodejs.org/api/packages.html#dual-package-hazard)):
|
|
63
65
|
|
|
64
66
|
```jsonc
|
|
65
67
|
{
|
|
66
68
|
"name": "lib", // Package name
|
|
67
69
|
"exports": {
|
|
68
70
|
".": {
|
|
69
|
-
"source": "src/index.ts(x)?", // Source code
|
|
70
|
-
"types": "./dist/index.d.ts", // Typing output file (if defined, can increase build time)
|
|
71
|
-
"
|
|
71
|
+
"source": "src/index.ts(x)?", // Source code entry point.
|
|
72
|
+
"types": "./dist/index.d.ts", // // Typing output file (if defined, can increase build time). This condition should always come first after the custom `source` field definition.
|
|
73
|
+
"require": "./dist/index.cjs", // CommonJS output file (matches when the module is loaded via require() consumer side).
|
|
74
|
+
"import": "./dist/index.mjs", // ESM output file (matches when the package is loaded via import or import() consumer side).
|
|
75
|
+
"default": "./dist/index.mjs", // By default, Quickbundle will always output ESM format for the `default` field (this condition should always come last since it always matches as a generic fallback). However, take care: if both `import` and `default` fields are defined, provide the same file path, as the `import` field export instruction will be the only one considered to define the output file path.
|
|
72
76
|
},
|
|
73
|
-
"./
|
|
77
|
+
"./otherModulePath": {
|
|
74
78
|
// ...
|
|
75
79
|
}
|
|
76
80
|
}
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,9 @@ import { readFile as readFile$1 } from 'node:fs/promises';
|
|
|
16
16
|
const onLog = (_, log)=>{
|
|
17
17
|
if (log.message.includes("Generated an empty chunk")) return;
|
|
18
18
|
};
|
|
19
|
+
const isRecord = (value)=>{
|
|
20
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
+
};
|
|
19
22
|
|
|
20
23
|
const build = async (configurations)=>{
|
|
21
24
|
var _process_env;
|
|
@@ -60,6 +63,20 @@ const createConfigurations = (options = {
|
|
|
60
63
|
minification: false,
|
|
61
64
|
sourceMaps: false
|
|
62
65
|
})=>{
|
|
66
|
+
return getBuildableExports().flatMap((buildableExport)=>{
|
|
67
|
+
return [
|
|
68
|
+
buildableExport.source && createMainConfig({
|
|
69
|
+
...buildableExport,
|
|
70
|
+
source: buildableExport.source
|
|
71
|
+
}, options),
|
|
72
|
+
buildableExport.source && buildableExport.types && createTypesConfig({
|
|
73
|
+
source: buildableExport.source,
|
|
74
|
+
types: buildableExport.types
|
|
75
|
+
})
|
|
76
|
+
].filter(Boolean);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const getBuildableExports = ()=>{
|
|
63
80
|
/**
|
|
64
81
|
* Entry-point resolution:
|
|
65
82
|
* Following the [package entry-point specification](https://nodejs.org/api/packages.html#package-entry-points),
|
|
@@ -68,34 +85,49 @@ const createConfigurations = (options = {
|
|
|
68
85
|
*/ if (PKG.main ?? PKG.module ?? PKG.types ?? !PKG.exports) {
|
|
69
86
|
throw new Error("Invalid package entry points contract. Use the recommended [`exports` field](https://nodejs.org/api/packages.html#package-entry-points) instead and, for TypeScript-based projects, update the `tsconfig.json` file to resolve it properly (`moduleResolution` must be set to `Bundler` (or `NodeNext`)).");
|
|
70
87
|
}
|
|
71
|
-
const
|
|
88
|
+
const buildableExportFields = [
|
|
72
89
|
"default",
|
|
73
90
|
"import",
|
|
74
91
|
"require",
|
|
75
92
|
"types"
|
|
76
93
|
];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
let singleExport = undefined;
|
|
95
|
+
const output = Object.entries(PKG.exports).map(([field, value])=>{
|
|
96
|
+
if (isRecord(value)) {
|
|
97
|
+
return [
|
|
98
|
+
field,
|
|
99
|
+
value
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
if ([
|
|
103
|
+
"source",
|
|
104
|
+
...buildableExportFields
|
|
105
|
+
].includes(field)) {
|
|
106
|
+
if (!singleExport) {
|
|
107
|
+
singleExport = {};
|
|
108
|
+
singleExport[field] = value;
|
|
109
|
+
return [
|
|
110
|
+
".",
|
|
111
|
+
singleExport
|
|
112
|
+
];
|
|
84
113
|
}
|
|
114
|
+
singleExport[field] = value;
|
|
85
115
|
}
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
return undefined;
|
|
117
|
+
}).reduce((buildableExports, currentExport)=>{
|
|
118
|
+
if (!currentExport) return buildableExports;
|
|
119
|
+
const [exportField, exportValue] = currentExport;
|
|
120
|
+
const conditionalExportFields = Object.keys(exportValue);
|
|
121
|
+
if (!conditionalExportFields.includes("source")) return buildableExports;
|
|
122
|
+
const hasAtLeastOneRequiredField = buildableExportFields.some((entryPointField)=>conditionalExportFields.includes(entryPointField));
|
|
123
|
+
if (hasAtLeastOneRequiredField) {
|
|
124
|
+
buildableExports.push(exportValue);
|
|
125
|
+
return buildableExports;
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`A \`source\` field is defined without an output defined for the \`${exportField}\` export. Make sure to define at least one conditional entry point (including ${buildableExportFields.map((field)=>`\`${field}\``).join(", ")})`);
|
|
128
|
+
}, []);
|
|
97
129
|
if (output.length === 0) {
|
|
98
|
-
throw new Error("No `source` field is set for the targeted package. If a build step is necessary, make sure to configure at least one `source` field in the package `exports` contract.");
|
|
130
|
+
throw new Error("No `source` field is set for the targeted package. If a build step is necessary, make sure to configure at least one `source` field in the package `exports` contract. If not, do not execute quickbundle on this package.");
|
|
99
131
|
}
|
|
100
132
|
return output;
|
|
101
133
|
};
|
|
@@ -130,7 +162,7 @@ const createMainConfig = (entryPoints, options)=>{
|
|
|
130
162
|
const { minification, sourceMaps } = options;
|
|
131
163
|
const esmInput = entryPoints.import ?? entryPoints.default;
|
|
132
164
|
if (entryPoints.import && entryPoints.default && entryPoints.import !== entryPoints.default) {
|
|
133
|
-
throw new Error("Both `import` and `default` export fields have been defined but with different values. To preserve proper `default` field resolution on the consumer side, make sure to provide the same file path for both fields
|
|
165
|
+
throw new Error("Both `import` and `default` export fields have been defined but with different values. To preserve proper `default` field resolution on the consumer side (i.e. to target ESM format), make sure to provide the same file path for both fields.");
|
|
134
166
|
}
|
|
135
167
|
const output = [
|
|
136
168
|
entryPoints.require && {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quickbundle",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "The zero-configuration transpiler and bundler for the web",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ayoub Adib",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
50
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
51
51
|
"@rollup/plugin-json": "^6.1.0",
|
|
52
52
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
53
53
|
"@rollup/plugin-url": "^8.0.2",
|