quickbundle 2.2.0 → 2.3.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 CHANGED
@@ -34,6 +34,33 @@ yarn add quickbundle
34
34
 
35
35
  2️⃣ Set up your package configuration (`package.json`):
36
36
 
37
+ - When exporting both CommonJS (CJS) and ECMAScript Modules (ESM) format:
38
+
39
+ ```jsonc
40
+ {
41
+ "name": "lib", // Package name
42
+ "exports": {
43
+ ".": {
44
+ "source": "src/index.ts(x)?", // Source code entrypoint
45
+ "types": "./dist/index.d.ts", // Typing output file (if defined, can increase build time)
46
+ "import": "./dist/index.mjs", // ESM output file (matches when the package is loaded via import or import() consumer side)
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.
49
+ },
50
+ "./otherSubModule": {
51
+ // ...
52
+ }
53
+ }
54
+ "scripts": {
55
+ "build": "quickbundle build", // Production mode (optimizes bundle)
56
+ "watch": "quickbundle watch", // Development mode (watches each file change)
57
+ },
58
+ // ...
59
+ }
60
+ ```
61
+
62
+ - When exporting exclusively ESM format:
63
+
37
64
  ```jsonc
38
65
  {
39
66
  "name": "lib", // Package name
@@ -41,8 +68,10 @@ yarn add quickbundle
41
68
  ".": {
42
69
  "source": "src/index.ts(x)?", // Source code entrypoint
43
70
  "types": "./dist/index.d.ts", // Typing output file (if defined, can increase build time)
44
- "import": "./dist/index.mjs", // ESM output file
45
- "require": "./dist/index.cjs" // CommonJS output file
71
+ "default": "./dist/index.js", // 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.
72
+ },
73
+ "./otherSubModule": {
74
+ // ...
46
75
  }
47
76
  }
48
77
  "scripts": {
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ const createConfigurations = (options = {
69
69
  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
70
  }
71
71
  const outputEntryPointFields = [
72
+ "default",
72
73
  "import",
73
74
  "require",
74
75
  "types"
@@ -127,14 +128,18 @@ const getPlugins = (...customPlugins)=>{
127
128
  };
128
129
  const createMainConfig = (entryPoints, options)=>{
129
130
  const { minification, sourceMaps } = options;
131
+ const esmInput = entryPoints.import ?? entryPoints.default;
132
+ 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, as the `import` field export instruction will be the only one considered to define the output file path.");
134
+ }
130
135
  const output = [
131
136
  entryPoints.require && {
132
137
  file: entryPoints.require,
133
138
  format: "cjs",
134
139
  sourcemap: sourceMaps
135
140
  },
136
- entryPoints.import && {
137
- file: entryPoints.import,
141
+ esmInput && {
142
+ file: esmInput,
138
143
  format: "es",
139
144
  sourcemap: sourceMaps
140
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickbundle",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "The zero-configuration transpiler and bundler for the web",
5
5
  "author": {
6
6
  "name": "Ayoub Adib",