@hypernym/bundler 0.13.1 → 0.14.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 +49 -18
- package/dist/bin/index.mjs +61 -76
- package/dist/index.cjs +26 -0
- package/dist/types/{index.d.ts → index.d.cts} +106 -28
- package/dist/types/index.d.mts +708 -0
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
58
58
|
export default defineConfig({
|
|
59
59
|
entries: [
|
|
60
60
|
{ input: './src/index.ts' },
|
|
61
|
-
{
|
|
61
|
+
{ dts: './src/types/index.ts' },
|
|
62
62
|
{
|
|
63
63
|
input: './src/utils/index.ts',
|
|
64
64
|
output: './dist/utils/utils.min.mjs',
|
|
@@ -99,11 +99,34 @@ Set a custom config path via the CLI command:
|
|
|
99
99
|
npx hyperbundler --config hyper.config.ts
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
##
|
|
102
|
+
## Formats
|
|
103
|
+
|
|
104
|
+
During transformation, file formats are automatically resolved and in most cases there is no need for additional configuration.
|
|
105
|
+
|
|
106
|
+
`Hyperbundler` module environment for generated files defaults to `esm`, which means the outputs will have a `.mjs` extension unless otherwise specified. For TypeScript declarations, the appropriate extension will be `.d.mts`.
|
|
107
|
+
|
|
108
|
+
Formats can also be explicitly specified for each entry, if necessary.
|
|
109
|
+
|
|
110
|
+
### Inputs
|
|
111
|
+
|
|
112
|
+
Default transformation behaviour for all `chunk` entries:
|
|
113
|
+
|
|
114
|
+
- `./srcDir/file.js` resolves to `./outDir/file.mjs`
|
|
115
|
+
- `./srcDir/file.mjs` resolves to `./outDir/file.mjs`
|
|
116
|
+
- `./srcDir/file.cjs` resolves to `./outDir/file.cjs`
|
|
117
|
+
- `./srcDir/file.ts` resolves to `./outDir/file.mjs`
|
|
118
|
+
- `./srcDir/file.mts` resolves to `./outDir/file.mjs`
|
|
119
|
+
- `./srcDir/file.cts` resolves to `./outDir/file.cjs`
|
|
103
120
|
|
|
104
|
-
|
|
121
|
+
### Declarations
|
|
105
122
|
|
|
106
|
-
|
|
123
|
+
Default transformation behaviour for all `dts` entries:
|
|
124
|
+
|
|
125
|
+
- `./srcDir/file.ts` resolves to `./outDir/file.d.mts`
|
|
126
|
+
|
|
127
|
+
## Options
|
|
128
|
+
|
|
129
|
+
All options are documented with descriptions and examples so auto-completion will be offered as you type. Simply hover over the property and see what it does in the `quickinfo`.
|
|
107
130
|
|
|
108
131
|
### entries
|
|
109
132
|
|
|
@@ -121,7 +144,7 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
121
144
|
export default defineConfig({
|
|
122
145
|
entries: [
|
|
123
146
|
{ input: './src/index.ts' }, // => './dist/index.mjs'
|
|
124
|
-
{
|
|
147
|
+
{ dts: './src/types.ts' }, // => './dist/types.d.mts'
|
|
125
148
|
// ...
|
|
126
149
|
],
|
|
127
150
|
})
|
|
@@ -140,9 +163,7 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
140
163
|
|
|
141
164
|
export default defineConfig({
|
|
142
165
|
entries: [
|
|
143
|
-
{
|
|
144
|
-
input: './src/index.ts', // => './dist/index.mjs'
|
|
145
|
-
},
|
|
166
|
+
{ input: './src/index.ts' }, // => './dist/index.mjs'
|
|
146
167
|
],
|
|
147
168
|
})
|
|
148
169
|
```
|
|
@@ -160,9 +181,19 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
160
181
|
|
|
161
182
|
export default defineConfig({
|
|
162
183
|
entries: [
|
|
163
|
-
{
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
{ declaration: './src/types.ts' }, // => './dist/types.d.mts'
|
|
185
|
+
],
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Also, it is possible to use `dts` alias.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { defineConfig } from '@hypernym/bundler'
|
|
193
|
+
|
|
194
|
+
export default defineConfig({
|
|
195
|
+
entries: [
|
|
196
|
+
{ dts: './src/types.ts' }, // => './dist/types.d.mts'
|
|
166
197
|
],
|
|
167
198
|
})
|
|
168
199
|
```
|
|
@@ -373,7 +404,7 @@ export default defineConfig({
|
|
|
373
404
|
|
|
374
405
|
### build:entry:start
|
|
375
406
|
|
|
376
|
-
- Type: `(
|
|
407
|
+
- Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>`
|
|
377
408
|
- Default: `undefined`
|
|
378
409
|
|
|
379
410
|
Called on each entry just before the build process.
|
|
@@ -388,12 +419,12 @@ import { plugin1, plugin2 } from './src/utils/plugins.js'
|
|
|
388
419
|
|
|
389
420
|
export default defineConfig({
|
|
390
421
|
hooks: {
|
|
391
|
-
'build:entry:start': async (
|
|
422
|
+
'build:entry:start': async (entry, stats) => {
|
|
392
423
|
// adds custom plugins for a specific entry only
|
|
393
|
-
if (
|
|
394
|
-
|
|
424
|
+
if (entry.input?.includes('./src/index.ts')) {
|
|
425
|
+
entry.defaultPlugins = [
|
|
395
426
|
plugin1(), // adds a custom plugin before the default bundler plugins
|
|
396
|
-
...
|
|
427
|
+
...entry.defaultPlugins, // list of default bundler plugins
|
|
397
428
|
plugin2(), // adds a custom plugin after the default bundler plugins
|
|
398
429
|
]
|
|
399
430
|
}
|
|
@@ -404,7 +435,7 @@ export default defineConfig({
|
|
|
404
435
|
|
|
405
436
|
### build:entry:end
|
|
406
437
|
|
|
407
|
-
- Type: `(
|
|
438
|
+
- Type: `(entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>`
|
|
408
439
|
- Default: `undefined`
|
|
409
440
|
|
|
410
441
|
Called on each entry right after the build process is completed.
|
|
@@ -416,7 +447,7 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
416
447
|
|
|
417
448
|
export default defineConfig({
|
|
418
449
|
hooks: {
|
|
419
|
-
'build:entry:end': async (
|
|
450
|
+
'build:entry:end': async (entry, stats) => {
|
|
420
451
|
// ...
|
|
421
452
|
},
|
|
422
453
|
},
|
package/dist/bin/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ const externals = [
|
|
|
25
25
|
];
|
|
26
26
|
|
|
27
27
|
const logo = `\u2726\u2726`;
|
|
28
|
-
const version = `0.
|
|
28
|
+
const version = `0.14.0`;
|
|
29
29
|
|
|
30
30
|
const cl = console.log;
|
|
31
31
|
const separator = `/`;
|
|
@@ -73,37 +73,33 @@ function formatBytes(bytes) {
|
|
|
73
73
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${units[i]}`;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
function getOutputPath(outDir, input,
|
|
76
|
+
function getOutputPath(outDir, input, dts) {
|
|
77
77
|
const _input = input.startsWith("./") ? input.slice(2) : input;
|
|
78
78
|
let output = _input.replace(_input.split("/")[0], outDir);
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
if (output.endsWith(".ts")) output = `${output.slice(0, -2)}${
|
|
83
|
-
if (output.endsWith(".mts")) output = `${output.slice(0, -3)}${
|
|
84
|
-
if (output.endsWith(".cts")) output = `${output.slice(0, -3)}${cts}`;
|
|
79
|
+
const ext = dts ? "d.mts" : "mjs";
|
|
80
|
+
const cts = dts ? "d.cts" : "cjs";
|
|
81
|
+
if (output.endsWith(".js")) output = `${output.slice(0, -2)}${ext}`;
|
|
82
|
+
else if (output.endsWith(".ts")) output = `${output.slice(0, -2)}${ext}`;
|
|
83
|
+
else if (output.endsWith(".mts")) output = `${output.slice(0, -3)}${ext}`;
|
|
84
|
+
else if (output.endsWith(".cts")) output = `${output.slice(0, -3)}${cts}`;
|
|
85
85
|
if (outDir.startsWith("./") || outDir.startsWith("../")) return output;
|
|
86
|
-
return `./${output}`;
|
|
86
|
+
else return `./${output}`;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
function getLongestOutput(outDir, entries) {
|
|
90
90
|
const outputs = [];
|
|
91
91
|
for (const entry of entries) {
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
outputs.push(out);
|
|
95
|
-
}
|
|
96
|
-
if ("input" in entry && entry.input) {
|
|
92
|
+
if (entry.copy) outputs.push(entry.copy.output);
|
|
93
|
+
if (entry.input) {
|
|
97
94
|
const out = entry.output || getOutputPath(outDir, entry.input);
|
|
98
95
|
outputs.push(out);
|
|
99
96
|
}
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
97
|
+
if (entry.declaration || entry.dts) {
|
|
98
|
+
const dts = entry.declaration || entry.dts;
|
|
99
|
+
const out = entry.output || getOutputPath(outDir, dts, true);
|
|
102
100
|
outputs.push(out);
|
|
103
101
|
}
|
|
104
|
-
if (
|
|
105
|
-
outputs.push(entry.output);
|
|
106
|
-
}
|
|
102
|
+
if (entry.template) outputs.push(entry.output);
|
|
107
103
|
}
|
|
108
104
|
return Math.max(...outputs.map((v) => v.length));
|
|
109
105
|
}
|
|
@@ -301,6 +297,7 @@ async function build(cwd, options) {
|
|
|
301
297
|
else return `./${path}`;
|
|
302
298
|
};
|
|
303
299
|
const fileStats = {
|
|
300
|
+
cwd,
|
|
304
301
|
path: `${parseOutput(_entry.output)}/${parseInput(copyInput)}`,
|
|
305
302
|
size: totalSize,
|
|
306
303
|
buildTime: Date.now() - entryStart,
|
|
@@ -314,31 +311,22 @@ async function build(cwd, options) {
|
|
|
314
311
|
}
|
|
315
312
|
if (entry.input) {
|
|
316
313
|
const logFilter = getLogFilter(entry.logFilter || []);
|
|
317
|
-
const _output = getOutputPath(outDir, entry.input);
|
|
314
|
+
const _output = entry.output || getOutputPath(outDir, entry.input);
|
|
318
315
|
let _format = "esm";
|
|
319
316
|
if (_output.endsWith(".cjs")) _format = "cjs";
|
|
320
317
|
const buildLogs = [];
|
|
321
318
|
const _entry = {
|
|
322
319
|
input: entry.input,
|
|
323
|
-
output:
|
|
320
|
+
output: _output,
|
|
324
321
|
externals: entry.externals || options.externals,
|
|
325
322
|
format: entry.format || _format,
|
|
326
|
-
|
|
323
|
+
...entry,
|
|
327
324
|
defaultPlugins: [
|
|
328
325
|
esbuild({
|
|
329
326
|
minify: !isUndefined(entry.minify) ? entry.minify : options.minify,
|
|
330
327
|
...entry.transformers?.esbuild
|
|
331
328
|
})
|
|
332
|
-
]
|
|
333
|
-
plugins: entry.plugins,
|
|
334
|
-
banner: entry.banner,
|
|
335
|
-
footer: entry.footer,
|
|
336
|
-
intro: entry.intro,
|
|
337
|
-
outro: entry.outro,
|
|
338
|
-
paths: entry.paths,
|
|
339
|
-
name: entry.name,
|
|
340
|
-
globals: entry.globals,
|
|
341
|
-
extend: entry.extend
|
|
329
|
+
]
|
|
342
330
|
};
|
|
343
331
|
if (!entry.plugins) {
|
|
344
332
|
if (_entry.transformers?.json) {
|
|
@@ -348,7 +336,7 @@ async function build(cwd, options) {
|
|
|
348
336
|
if (_entry.transformers?.replace) {
|
|
349
337
|
_entry.defaultPlugins.unshift(
|
|
350
338
|
replacePlugin({
|
|
351
|
-
|
|
339
|
+
preventAssignment: true,
|
|
352
340
|
..._entry.transformers.replace
|
|
353
341
|
})
|
|
354
342
|
);
|
|
@@ -361,7 +349,15 @@ async function build(cwd, options) {
|
|
|
361
349
|
aliasPlugin(_entry.transformers?.alias || aliasOptions)
|
|
362
350
|
);
|
|
363
351
|
}
|
|
364
|
-
|
|
352
|
+
const fileStats = {
|
|
353
|
+
cwd,
|
|
354
|
+
path: _entry.output,
|
|
355
|
+
size: 0,
|
|
356
|
+
buildTime: entryStart,
|
|
357
|
+
format: _entry.format,
|
|
358
|
+
logs: buildLogs
|
|
359
|
+
};
|
|
360
|
+
await hooks?.["build:entry:start"]?.(_entry, fileStats);
|
|
365
361
|
const _build = await rollup({
|
|
366
362
|
input: resolve(cwd, _entry.input),
|
|
367
363
|
external: _entry.externals,
|
|
@@ -383,46 +379,42 @@ async function build(cwd, options) {
|
|
|
383
379
|
extend: _entry.extend
|
|
384
380
|
});
|
|
385
381
|
const stats = await stat(resolve(cwd, _entry.output));
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
format: _entry.format,
|
|
391
|
-
logs: buildLogs
|
|
392
|
-
};
|
|
393
|
-
buildStats.files.push(file);
|
|
382
|
+
fileStats.size = stats.size;
|
|
383
|
+
fileStats.buildTime = Date.now() - entryStart;
|
|
384
|
+
fileStats.logs = buildLogs;
|
|
385
|
+
buildStats.files.push(fileStats);
|
|
394
386
|
buildStats.size = buildStats.size + stats.size;
|
|
395
|
-
logModuleStats(
|
|
396
|
-
await hooks?.["build:entry:end"]?.(_entry,
|
|
387
|
+
logModuleStats(fileStats, longestOutput);
|
|
388
|
+
await hooks?.["build:entry:end"]?.(_entry, fileStats);
|
|
397
389
|
}
|
|
398
|
-
if (entry.declaration) {
|
|
390
|
+
if (entry.dts || entry.declaration) {
|
|
399
391
|
const logFilter = getLogFilter(entry.logFilter || []);
|
|
400
|
-
const _output = getOutputPath(outDir, entry.declaration, true);
|
|
401
|
-
let _format = "esm";
|
|
402
|
-
if (_output.endsWith(".d.cts")) _format = "cjs";
|
|
403
392
|
const buildLogs = [];
|
|
393
|
+
const dts$1 = entry.dts || entry.declaration;
|
|
404
394
|
const _entry = {
|
|
405
|
-
|
|
406
|
-
output: entry.output ||
|
|
395
|
+
dts: dts$1,
|
|
396
|
+
output: entry.output || getOutputPath(outDir, dts$1, true),
|
|
407
397
|
externals: entry.externals || options.externals,
|
|
408
|
-
format: entry.format ||
|
|
409
|
-
|
|
410
|
-
defaultPlugins: [dts(entry.transformers?.dts)]
|
|
411
|
-
plugins: entry.plugins,
|
|
412
|
-
banner: entry.banner,
|
|
413
|
-
footer: entry.footer,
|
|
414
|
-
intro: entry.intro,
|
|
415
|
-
outro: entry.outro,
|
|
416
|
-
paths: entry.paths
|
|
398
|
+
format: entry.format || "esm",
|
|
399
|
+
...entry,
|
|
400
|
+
defaultPlugins: [dts(entry.transformers?.dts)]
|
|
417
401
|
};
|
|
418
402
|
if (!entry.plugins) {
|
|
419
403
|
_entry.defaultPlugins.unshift(
|
|
420
404
|
aliasPlugin(_entry.transformers?.alias || aliasOptions)
|
|
421
405
|
);
|
|
422
406
|
}
|
|
423
|
-
|
|
407
|
+
const fileStats = {
|
|
408
|
+
cwd,
|
|
409
|
+
path: _entry.output,
|
|
410
|
+
size: 0,
|
|
411
|
+
buildTime: entryStart,
|
|
412
|
+
format: "dts",
|
|
413
|
+
logs: buildLogs
|
|
414
|
+
};
|
|
415
|
+
await hooks?.["build:entry:start"]?.(_entry, fileStats);
|
|
424
416
|
const _build = await rollup({
|
|
425
|
-
input: resolve(cwd, _entry.
|
|
417
|
+
input: resolve(cwd, _entry.dts),
|
|
426
418
|
external: _entry.externals,
|
|
427
419
|
plugins: _entry.plugins || _entry.defaultPlugins,
|
|
428
420
|
onLog: (level, log) => {
|
|
@@ -439,28 +431,21 @@ async function build(cwd, options) {
|
|
|
439
431
|
paths: _entry.paths
|
|
440
432
|
});
|
|
441
433
|
const stats = await stat(resolve(cwd, _entry.output));
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
buildTime: Date.now() - entryStart,
|
|
446
|
-
format: "dts",
|
|
447
|
-
logs: buildLogs
|
|
448
|
-
};
|
|
434
|
+
fileStats.size = stats.size;
|
|
435
|
+
fileStats.buildTime = Date.now() - entryStart;
|
|
436
|
+
fileStats.logs = buildLogs;
|
|
449
437
|
buildStats.files.push(fileStats);
|
|
450
438
|
buildStats.size = buildStats.size + stats.size;
|
|
451
439
|
logModuleStats(fileStats, longestOutput);
|
|
452
|
-
await hooks?.["build:entry:end"]?.(_entry,
|
|
440
|
+
await hooks?.["build:entry:end"]?.(_entry, fileStats);
|
|
453
441
|
}
|
|
454
442
|
if (entry.template && entry.output) {
|
|
455
443
|
const buildLogs = [];
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
output: entry.output
|
|
459
|
-
};
|
|
460
|
-
await write(_entry.output, _entry.template);
|
|
461
|
-
const stats = await stat(resolve(cwd, _entry.output));
|
|
444
|
+
await write(entry.output, entry.template);
|
|
445
|
+
const stats = await stat(resolve(cwd, entry.output));
|
|
462
446
|
const fileStats = {
|
|
463
|
-
|
|
447
|
+
cwd,
|
|
448
|
+
path: entry.output,
|
|
464
449
|
size: stats.size,
|
|
465
450
|
buildTime: Date.now() - entryStart,
|
|
466
451
|
format: "tmp",
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const externals = [
|
|
4
|
+
/^node:/,
|
|
5
|
+
/^@types/,
|
|
6
|
+
/^@rollup/,
|
|
7
|
+
/^@hypernym/,
|
|
8
|
+
/^rollup/
|
|
9
|
+
];
|
|
10
|
+
function defineConfig(options) {
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function resolvePaths(options) {
|
|
15
|
+
return (id) => {
|
|
16
|
+
for (const resolver of options) {
|
|
17
|
+
const { find, replacement } = resolver;
|
|
18
|
+
if (id.match(find)) id = replacement;
|
|
19
|
+
}
|
|
20
|
+
return id;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.defineConfig = defineConfig;
|
|
25
|
+
exports.externals = externals;
|
|
26
|
+
exports.resolvePaths = resolvePaths;
|
|
@@ -82,11 +82,34 @@ interface EntryBase {
|
|
|
82
82
|
interface EntryChunk extends EntryBase {
|
|
83
83
|
/**
|
|
84
84
|
* Specifies the path of the build source.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* export default defineConfig({
|
|
90
|
+
* entries: [
|
|
91
|
+
* { input: './src/index.ts' }, // => './dist/index.mjs'
|
|
92
|
+
* ]
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
85
95
|
*/
|
|
86
96
|
input?: string;
|
|
87
97
|
/**
|
|
88
98
|
* Specifies the path of the transformed file.
|
|
89
99
|
*
|
|
100
|
+
* @example
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* export default defineConfig({
|
|
104
|
+
* entries: [
|
|
105
|
+
* {
|
|
106
|
+
* input: './src/index.ts',
|
|
107
|
+
* output: './out/index.js', // => './out/index.js'
|
|
108
|
+
* },
|
|
109
|
+
* ]
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
90
113
|
* @default undefined
|
|
91
114
|
*/
|
|
92
115
|
output?: string;
|
|
@@ -133,17 +156,57 @@ interface EntryChunk extends EntryBase {
|
|
|
133
156
|
*/
|
|
134
157
|
minify?: boolean;
|
|
135
158
|
declaration?: never;
|
|
159
|
+
dts?: never;
|
|
136
160
|
copy?: never;
|
|
137
161
|
template?: never;
|
|
138
162
|
}
|
|
139
163
|
interface EntryDeclaration extends EntryBase {
|
|
140
164
|
/**
|
|
141
165
|
* Specifies the path of the TypeScript `declaration` build source.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* export default defineConfig({
|
|
171
|
+
* entries: [
|
|
172
|
+
* { dts: './src/types.ts' }, // => './dist/types.d.mts'
|
|
173
|
+
* ]
|
|
174
|
+
* })
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
dts?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Specifies the path of the TypeScript `declaration` build source.
|
|
180
|
+
*
|
|
181
|
+
* Also, it is possible to use `dts` alias.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
*
|
|
185
|
+
* ```ts
|
|
186
|
+
* export default defineConfig({
|
|
187
|
+
* entries: [
|
|
188
|
+
* { declaration: './src/types.ts' }, // => './dist/types.d.mts'
|
|
189
|
+
* ]
|
|
190
|
+
* })
|
|
191
|
+
* ```
|
|
142
192
|
*/
|
|
143
193
|
declaration?: string;
|
|
144
194
|
/**
|
|
145
195
|
* Specifies the path of the TypeScript transformed `declaration` file.
|
|
146
196
|
*
|
|
197
|
+
* @example
|
|
198
|
+
*
|
|
199
|
+
* ```ts
|
|
200
|
+
* export default defineConfig({
|
|
201
|
+
* entries: [
|
|
202
|
+
* {
|
|
203
|
+
* dts: './src/types.ts',
|
|
204
|
+
* output: './out/types.d.ts', // => './out/types.d.ts'
|
|
205
|
+
* },
|
|
206
|
+
* ]
|
|
207
|
+
* })
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
147
210
|
* @default undefined
|
|
148
211
|
*/
|
|
149
212
|
output?: string;
|
|
@@ -216,6 +279,7 @@ interface EntryCopy {
|
|
|
216
279
|
copy?: CopyOptions;
|
|
217
280
|
input?: never;
|
|
218
281
|
declaration?: never;
|
|
282
|
+
dts?: never;
|
|
219
283
|
template?: never;
|
|
220
284
|
name?: never;
|
|
221
285
|
globals?: never;
|
|
@@ -248,6 +312,7 @@ interface EntryTemplate {
|
|
|
248
312
|
output: string;
|
|
249
313
|
input?: never;
|
|
250
314
|
declaration?: never;
|
|
315
|
+
dts?: never;
|
|
251
316
|
copy?: never;
|
|
252
317
|
name?: never;
|
|
253
318
|
globals?: never;
|
|
@@ -268,7 +333,7 @@ interface Options {
|
|
|
268
333
|
* export default defineConfig({
|
|
269
334
|
* entries: [
|
|
270
335
|
* { input: './src/index.ts' }, // => './dist/index.mjs'
|
|
271
|
-
* {
|
|
336
|
+
* { dts: './src/types.ts' }, // => './dist/types.d.mts'
|
|
272
337
|
* // ...
|
|
273
338
|
* ]
|
|
274
339
|
* })
|
|
@@ -392,6 +457,32 @@ interface BuildLogs {
|
|
|
392
457
|
level: LogLevel;
|
|
393
458
|
log: RollupLog;
|
|
394
459
|
}
|
|
460
|
+
interface BuildEntryStats {
|
|
461
|
+
/**
|
|
462
|
+
* The root path of the project.
|
|
463
|
+
*/
|
|
464
|
+
cwd: string;
|
|
465
|
+
/**
|
|
466
|
+
* Module output path.
|
|
467
|
+
*/
|
|
468
|
+
path: string;
|
|
469
|
+
/**
|
|
470
|
+
* Module size.
|
|
471
|
+
*/
|
|
472
|
+
size: number;
|
|
473
|
+
/**
|
|
474
|
+
* Build time of individual module.
|
|
475
|
+
*/
|
|
476
|
+
buildTime: number;
|
|
477
|
+
/**
|
|
478
|
+
* Module format.
|
|
479
|
+
*/
|
|
480
|
+
format: string;
|
|
481
|
+
/**
|
|
482
|
+
* List of warnings from build plugins.
|
|
483
|
+
*/
|
|
484
|
+
logs: BuildLogs[];
|
|
485
|
+
}
|
|
395
486
|
interface BuildStats {
|
|
396
487
|
/**
|
|
397
488
|
* The root path of the project.
|
|
@@ -408,30 +499,17 @@ interface BuildStats {
|
|
|
408
499
|
/**
|
|
409
500
|
* List of generated bundle modules.
|
|
410
501
|
*/
|
|
411
|
-
files:
|
|
412
|
-
/**
|
|
413
|
-
* Module output path.
|
|
414
|
-
*/
|
|
415
|
-
path: string;
|
|
416
|
-
/**
|
|
417
|
-
* Module size.
|
|
418
|
-
*/
|
|
419
|
-
size: number;
|
|
420
|
-
/**
|
|
421
|
-
* Build time of individual module.
|
|
422
|
-
*/
|
|
423
|
-
buildTime: number;
|
|
424
|
-
/**
|
|
425
|
-
* Module format.
|
|
426
|
-
*/
|
|
427
|
-
format: string;
|
|
428
|
-
/**
|
|
429
|
-
* List of warnings from build plugins.
|
|
430
|
-
*/
|
|
431
|
-
logs: BuildLogs[];
|
|
432
|
-
}[];
|
|
502
|
+
files: BuildEntryStats[];
|
|
433
503
|
}
|
|
434
|
-
|
|
504
|
+
type PickEntryChunkOptions = 'input' | 'name' | 'globals' | 'extend' | 'minify' | 'transformers';
|
|
505
|
+
type PickEntryDtsOptions = 'declaration' | 'dts' | 'transformers';
|
|
506
|
+
interface BuildEntryOptions extends EntryBase, Pick<EntryChunk, PickEntryChunkOptions>, Pick<EntryDeclaration, PickEntryDtsOptions> {
|
|
507
|
+
/**
|
|
508
|
+
* Specifies the path of the transformed file.
|
|
509
|
+
*
|
|
510
|
+
* @default undefined
|
|
511
|
+
*/
|
|
512
|
+
output?: string;
|
|
435
513
|
/**
|
|
436
514
|
* Specifies options for default plugins.
|
|
437
515
|
*
|
|
@@ -491,7 +569,7 @@ interface HooksOptions {
|
|
|
491
569
|
* ```ts
|
|
492
570
|
* export default defineConfig({
|
|
493
571
|
* hooks: {
|
|
494
|
-
* 'build:entry:start': async (
|
|
572
|
+
* 'build:entry:start': async (entry, stats) => {
|
|
495
573
|
* // ...
|
|
496
574
|
* }
|
|
497
575
|
* }
|
|
@@ -500,7 +578,7 @@ interface HooksOptions {
|
|
|
500
578
|
*
|
|
501
579
|
* @default undefined
|
|
502
580
|
*/
|
|
503
|
-
'build:entry:start'?: (
|
|
581
|
+
'build:entry:start'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
|
|
504
582
|
/**
|
|
505
583
|
* Called on each entry right after the build process is completed.
|
|
506
584
|
*
|
|
@@ -509,7 +587,7 @@ interface HooksOptions {
|
|
|
509
587
|
* ```ts
|
|
510
588
|
* export default defineConfig({
|
|
511
589
|
* hooks: {
|
|
512
|
-
* 'build:entry:end': async (
|
|
590
|
+
* 'build:entry:end': async (entry, stats) => {
|
|
513
591
|
* // ...
|
|
514
592
|
* }
|
|
515
593
|
* }
|
|
@@ -518,7 +596,7 @@ interface HooksOptions {
|
|
|
518
596
|
*
|
|
519
597
|
* @default undefined
|
|
520
598
|
*/
|
|
521
|
-
'build:entry:end'?: (
|
|
599
|
+
'build:entry:end'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
|
|
522
600
|
/**
|
|
523
601
|
* Called right after building is complete.
|
|
524
602
|
*
|
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import { OutputOptions, Plugin, LogLevel, RollupLog } from 'rollup';
|
|
2
|
+
import { RollupReplaceOptions } from '@rollup/plugin-replace';
|
|
3
|
+
import { RollupJsonOptions } from '@rollup/plugin-json';
|
|
4
|
+
import { RollupNodeResolveOptions } from '@rollup/plugin-node-resolve';
|
|
5
|
+
import { RollupAliasOptions, Alias } from '@rollup/plugin-alias';
|
|
6
|
+
import { TransformOptions } from 'esbuild';
|
|
7
|
+
import { Options as Options$1 } from 'rollup-plugin-dts';
|
|
8
|
+
|
|
9
|
+
interface TransformersChunk {
|
|
10
|
+
esbuild?: TransformOptions;
|
|
11
|
+
resolve?: RollupNodeResolveOptions | true;
|
|
12
|
+
replace?: RollupReplaceOptions;
|
|
13
|
+
json?: RollupJsonOptions | true;
|
|
14
|
+
alias?: RollupAliasOptions;
|
|
15
|
+
}
|
|
16
|
+
interface TransformersDeclaration {
|
|
17
|
+
dts?: Options$1;
|
|
18
|
+
alias?: RollupAliasOptions;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface EntryBase {
|
|
22
|
+
/**
|
|
23
|
+
* Specifies the format of the generated module.
|
|
24
|
+
*
|
|
25
|
+
* @default 'esm'
|
|
26
|
+
*/
|
|
27
|
+
format?: OutputOptions['format'];
|
|
28
|
+
/**
|
|
29
|
+
* Specifies the module IDs, or regular expressions to match module IDs,
|
|
30
|
+
* that should remain external to the bundle.
|
|
31
|
+
*
|
|
32
|
+
* If not specified, infers the IDs from the global `options.externals` option.
|
|
33
|
+
*
|
|
34
|
+
* @default undefined
|
|
35
|
+
*/
|
|
36
|
+
externals?: (string | RegExp)[];
|
|
37
|
+
/**
|
|
38
|
+
* Specifies the string to be inserted at the beginning of the module.
|
|
39
|
+
*
|
|
40
|
+
* @default undefined
|
|
41
|
+
*/
|
|
42
|
+
banner?: OutputOptions['banner'];
|
|
43
|
+
/**
|
|
44
|
+
* Specifies the string to be inserted at the end of the module.
|
|
45
|
+
*
|
|
46
|
+
* @default undefined
|
|
47
|
+
*/
|
|
48
|
+
footer?: OutputOptions['footer'];
|
|
49
|
+
/**
|
|
50
|
+
* Specifies the code at the beginning that goes inside any _format-specific_ wrapper.
|
|
51
|
+
*
|
|
52
|
+
* @default undefined
|
|
53
|
+
*/
|
|
54
|
+
intro?: OutputOptions['intro'];
|
|
55
|
+
/**
|
|
56
|
+
* Specifies the code at the end that goes inside any _format-specific_ wrapper.
|
|
57
|
+
*
|
|
58
|
+
* @default undefined
|
|
59
|
+
*/
|
|
60
|
+
outro?: OutputOptions['outro'];
|
|
61
|
+
/**
|
|
62
|
+
* Maps external module IDs to paths.
|
|
63
|
+
*
|
|
64
|
+
* @default undefined
|
|
65
|
+
*/
|
|
66
|
+
paths?: OutputOptions['paths'];
|
|
67
|
+
/**
|
|
68
|
+
* Specifies custom filters that will display only certain log messages.
|
|
69
|
+
*
|
|
70
|
+
* @default undefined
|
|
71
|
+
*/
|
|
72
|
+
logFilter?: string[];
|
|
73
|
+
/**
|
|
74
|
+
* Specifies `rollup` plugins.
|
|
75
|
+
*
|
|
76
|
+
* Adding custom plugins disables all built-in `transformers` for full customization.
|
|
77
|
+
*
|
|
78
|
+
* @default undefined
|
|
79
|
+
*/
|
|
80
|
+
plugins?: Plugin[];
|
|
81
|
+
}
|
|
82
|
+
interface EntryChunk extends EntryBase {
|
|
83
|
+
/**
|
|
84
|
+
* Specifies the path of the build source.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* export default defineConfig({
|
|
90
|
+
* entries: [
|
|
91
|
+
* { input: './src/index.ts' }, // => './dist/index.mjs'
|
|
92
|
+
* ]
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
input?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Specifies the path of the transformed file.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* export default defineConfig({
|
|
104
|
+
* entries: [
|
|
105
|
+
* {
|
|
106
|
+
* input: './src/index.ts',
|
|
107
|
+
* output: './out/index.js', // => './out/index.js'
|
|
108
|
+
* },
|
|
109
|
+
* ]
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @default undefined
|
|
114
|
+
*/
|
|
115
|
+
output?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Specifies the built-in `transformers` options.
|
|
118
|
+
*
|
|
119
|
+
* Available transformers:
|
|
120
|
+
*
|
|
121
|
+
* - `esbuild`
|
|
122
|
+
* - `resolve`
|
|
123
|
+
* - `replace`
|
|
124
|
+
* - `json`
|
|
125
|
+
* - `alias`
|
|
126
|
+
*
|
|
127
|
+
* @default undefined
|
|
128
|
+
*/
|
|
129
|
+
transformers?: TransformersChunk;
|
|
130
|
+
/**
|
|
131
|
+
* Specifies the global variable name that representing exported bundle.
|
|
132
|
+
*
|
|
133
|
+
* Intended for `umd/iife` formats.
|
|
134
|
+
*
|
|
135
|
+
* @default undefined
|
|
136
|
+
*/
|
|
137
|
+
name?: OutputOptions['name'];
|
|
138
|
+
/**
|
|
139
|
+
* Specifies global _module ID_ and _variable name_ pairs necessary for external imports.
|
|
140
|
+
*
|
|
141
|
+
* Intended for `umd/iife` formats.
|
|
142
|
+
*
|
|
143
|
+
* @default undefined
|
|
144
|
+
*/
|
|
145
|
+
globals?: OutputOptions['globals'];
|
|
146
|
+
/**
|
|
147
|
+
* Specifies whether to extend the global variable defined by the `name` option.
|
|
148
|
+
*
|
|
149
|
+
* Intended for `umd/iife` formats.
|
|
150
|
+
*/
|
|
151
|
+
extend?: OutputOptions['extend'];
|
|
152
|
+
/**
|
|
153
|
+
* Minifies the generated code if enabled.
|
|
154
|
+
*
|
|
155
|
+
* @default undefined
|
|
156
|
+
*/
|
|
157
|
+
minify?: boolean;
|
|
158
|
+
declaration?: never;
|
|
159
|
+
dts?: never;
|
|
160
|
+
copy?: never;
|
|
161
|
+
template?: never;
|
|
162
|
+
}
|
|
163
|
+
interface EntryDeclaration extends EntryBase {
|
|
164
|
+
/**
|
|
165
|
+
* Specifies the path of the TypeScript `declaration` build source.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* export default defineConfig({
|
|
171
|
+
* entries: [
|
|
172
|
+
* { dts: './src/types.ts' }, // => './dist/types.d.mts'
|
|
173
|
+
* ]
|
|
174
|
+
* })
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
dts?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Specifies the path of the TypeScript `declaration` build source.
|
|
180
|
+
*
|
|
181
|
+
* Also, it is possible to use `dts` alias.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
*
|
|
185
|
+
* ```ts
|
|
186
|
+
* export default defineConfig({
|
|
187
|
+
* entries: [
|
|
188
|
+
* { declaration: './src/types.ts' }, // => './dist/types.d.mts'
|
|
189
|
+
* ]
|
|
190
|
+
* })
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
declaration?: string;
|
|
194
|
+
/**
|
|
195
|
+
* Specifies the path of the TypeScript transformed `declaration` file.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
*
|
|
199
|
+
* ```ts
|
|
200
|
+
* export default defineConfig({
|
|
201
|
+
* entries: [
|
|
202
|
+
* {
|
|
203
|
+
* dts: './src/types.ts',
|
|
204
|
+
* output: './out/types.d.ts', // => './out/types.d.ts'
|
|
205
|
+
* },
|
|
206
|
+
* ]
|
|
207
|
+
* })
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @default undefined
|
|
211
|
+
*/
|
|
212
|
+
output?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Specifies the built-in `transformers` options.
|
|
215
|
+
*
|
|
216
|
+
* Available transformers:
|
|
217
|
+
*
|
|
218
|
+
* - `dts`
|
|
219
|
+
* - `alias`
|
|
220
|
+
*
|
|
221
|
+
* @default undefined
|
|
222
|
+
*/
|
|
223
|
+
transformers?: TransformersDeclaration;
|
|
224
|
+
input?: never;
|
|
225
|
+
copy?: never;
|
|
226
|
+
template?: never;
|
|
227
|
+
name?: never;
|
|
228
|
+
globals?: never;
|
|
229
|
+
extend?: never;
|
|
230
|
+
minify?: never;
|
|
231
|
+
}
|
|
232
|
+
interface CopyOptions {
|
|
233
|
+
/**
|
|
234
|
+
* Specifies the path of the source.
|
|
235
|
+
*/
|
|
236
|
+
input: string | string[];
|
|
237
|
+
/**
|
|
238
|
+
* Specifies the path of the destination directory.
|
|
239
|
+
*/
|
|
240
|
+
output: string;
|
|
241
|
+
/**
|
|
242
|
+
* Copy directories recursively.
|
|
243
|
+
*
|
|
244
|
+
* @default true
|
|
245
|
+
*/
|
|
246
|
+
recursive?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Filters copied `files/directories`.
|
|
249
|
+
*
|
|
250
|
+
* Returns `true` to copy the item, `false` to ignore it.
|
|
251
|
+
*
|
|
252
|
+
* @default undefined
|
|
253
|
+
*/
|
|
254
|
+
filter?(source: string, destination: string): boolean;
|
|
255
|
+
}
|
|
256
|
+
interface EntryCopy {
|
|
257
|
+
/**
|
|
258
|
+
* Copies the single `file` or entire `directory` structure from source to destination, including subdirectories and files.
|
|
259
|
+
*
|
|
260
|
+
* This can be very useful for copying some assets that don't need a transformation process, but a simple copy paste feature.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
*
|
|
264
|
+
* ```ts
|
|
265
|
+
* export default defineConfig({
|
|
266
|
+
* entries: [
|
|
267
|
+
* {
|
|
268
|
+
* copy: {
|
|
269
|
+
* input: './src/path/file.ts', // or ['path-dir', 'path-file.ts', ...]
|
|
270
|
+
* output: './dist/out', // path to output dir
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
* ]
|
|
274
|
+
* })
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
277
|
+
* @default undefined
|
|
278
|
+
*/
|
|
279
|
+
copy?: CopyOptions;
|
|
280
|
+
input?: never;
|
|
281
|
+
declaration?: never;
|
|
282
|
+
dts?: never;
|
|
283
|
+
template?: never;
|
|
284
|
+
name?: never;
|
|
285
|
+
globals?: never;
|
|
286
|
+
extend?: never;
|
|
287
|
+
minify?: never;
|
|
288
|
+
}
|
|
289
|
+
interface EntryTemplate {
|
|
290
|
+
/**
|
|
291
|
+
* Specifies the content of the `template` file.
|
|
292
|
+
*
|
|
293
|
+
* Provides the ability to dynamically inject template content during the build phase.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
*
|
|
297
|
+
* ```ts
|
|
298
|
+
* export default defineConfig({
|
|
299
|
+
* entries: [
|
|
300
|
+
* {
|
|
301
|
+
* template: `// TypeScript code...`,
|
|
302
|
+
* output: './dist/template.ts',
|
|
303
|
+
* },
|
|
304
|
+
* ]
|
|
305
|
+
* })
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
template: string;
|
|
309
|
+
/**
|
|
310
|
+
* Specifies the path of the transformed `template` file.
|
|
311
|
+
*/
|
|
312
|
+
output: string;
|
|
313
|
+
input?: never;
|
|
314
|
+
declaration?: never;
|
|
315
|
+
dts?: never;
|
|
316
|
+
copy?: never;
|
|
317
|
+
name?: never;
|
|
318
|
+
globals?: never;
|
|
319
|
+
extend?: never;
|
|
320
|
+
minify?: never;
|
|
321
|
+
}
|
|
322
|
+
type EntryOptions = EntryChunk | EntryDeclaration | EntryCopy | EntryTemplate;
|
|
323
|
+
|
|
324
|
+
interface Options {
|
|
325
|
+
/**
|
|
326
|
+
* Specifies the bundle's entry points.
|
|
327
|
+
*
|
|
328
|
+
* It allows you to manually set all build entries and adjust options for each one individually.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
*
|
|
332
|
+
* ```ts
|
|
333
|
+
* export default defineConfig({
|
|
334
|
+
* entries: [
|
|
335
|
+
* { input: './src/index.ts' }, // => './dist/index.mjs'
|
|
336
|
+
* { dts: './src/types.ts' }, // => './dist/types.d.mts'
|
|
337
|
+
* // ...
|
|
338
|
+
* ]
|
|
339
|
+
* })
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
entries: EntryOptions[];
|
|
343
|
+
/**
|
|
344
|
+
* Specifies the output directory for production bundle.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
*
|
|
348
|
+
* ```ts
|
|
349
|
+
* export default defineConfig({
|
|
350
|
+
* outDir: 'output',
|
|
351
|
+
* })
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @default 'dist'
|
|
355
|
+
*/
|
|
356
|
+
outDir?: string;
|
|
357
|
+
/**
|
|
358
|
+
* Specifies the module IDs, or regular expressions to match module IDs,
|
|
359
|
+
* that should remain external to the bundle.
|
|
360
|
+
*
|
|
361
|
+
* IDs and regexps from this option are applied globally to all entries.
|
|
362
|
+
*
|
|
363
|
+
* Also, it is possible to define externals individually per entry (`entry.externals`).
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
*
|
|
367
|
+
* ```ts
|
|
368
|
+
* export default defineConfig({
|
|
369
|
+
* externals: ['id-1', 'id-2', /regexp/],
|
|
370
|
+
* })
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @default [/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]
|
|
374
|
+
*/
|
|
375
|
+
externals?: (string | RegExp)[];
|
|
376
|
+
/**
|
|
377
|
+
* Provides a powerful hooking system to further expand bundling mode.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
*
|
|
381
|
+
* ```ts
|
|
382
|
+
* export default defineConfig({
|
|
383
|
+
* hooks: {
|
|
384
|
+
* 'build:end': async (options, buildStats) => {
|
|
385
|
+
* // ...
|
|
386
|
+
* }
|
|
387
|
+
* }
|
|
388
|
+
* })
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* @default undefined
|
|
392
|
+
*/
|
|
393
|
+
hooks?: HooksOptions;
|
|
394
|
+
/**
|
|
395
|
+
* Specifies prefixes that will resolve imports with custom paths.
|
|
396
|
+
*
|
|
397
|
+
* Enables these `alias` by default:
|
|
398
|
+
*
|
|
399
|
+
* ```ts
|
|
400
|
+
* // Imports module from './src/utils/index.js'
|
|
401
|
+
* import { module } from '@/utils' // @
|
|
402
|
+
* import { module } from '~/utils' // ~
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* Also, it is possible to completely override the default aliases by setting custom ones.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
*
|
|
409
|
+
* ```ts
|
|
410
|
+
* export default defineConfig({
|
|
411
|
+
* alias: [
|
|
412
|
+
* { find: /^#/, replacement: resolve('./src') },
|
|
413
|
+
* ]
|
|
414
|
+
* })
|
|
415
|
+
* ```
|
|
416
|
+
*
|
|
417
|
+
* Now imports can be used like this:
|
|
418
|
+
*
|
|
419
|
+
* ```ts
|
|
420
|
+
* // Imports module from './src/utils/index.js'
|
|
421
|
+
* import { module } from '#/utils' // #
|
|
422
|
+
* ```
|
|
423
|
+
*
|
|
424
|
+
* @default undefined
|
|
425
|
+
*/
|
|
426
|
+
alias?: Alias[];
|
|
427
|
+
/**
|
|
428
|
+
* Specifies the minification for all `chunk` entries.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
*
|
|
432
|
+
* ```ts
|
|
433
|
+
* export default defineConfig({
|
|
434
|
+
* minify: true,
|
|
435
|
+
* })
|
|
436
|
+
* ```
|
|
437
|
+
*
|
|
438
|
+
* It can also be set per entry.
|
|
439
|
+
*
|
|
440
|
+
* ```ts
|
|
441
|
+
* export default defineConfig({
|
|
442
|
+
* entries: [
|
|
443
|
+
* {
|
|
444
|
+
* input: './src/index.ts',
|
|
445
|
+
* minify: true,
|
|
446
|
+
* },
|
|
447
|
+
* ],
|
|
448
|
+
* })
|
|
449
|
+
* ```
|
|
450
|
+
*
|
|
451
|
+
* @default undefined
|
|
452
|
+
*/
|
|
453
|
+
minify?: boolean;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
interface BuildLogs {
|
|
457
|
+
level: LogLevel;
|
|
458
|
+
log: RollupLog;
|
|
459
|
+
}
|
|
460
|
+
interface BuildEntryStats {
|
|
461
|
+
/**
|
|
462
|
+
* The root path of the project.
|
|
463
|
+
*/
|
|
464
|
+
cwd: string;
|
|
465
|
+
/**
|
|
466
|
+
* Module output path.
|
|
467
|
+
*/
|
|
468
|
+
path: string;
|
|
469
|
+
/**
|
|
470
|
+
* Module size.
|
|
471
|
+
*/
|
|
472
|
+
size: number;
|
|
473
|
+
/**
|
|
474
|
+
* Build time of individual module.
|
|
475
|
+
*/
|
|
476
|
+
buildTime: number;
|
|
477
|
+
/**
|
|
478
|
+
* Module format.
|
|
479
|
+
*/
|
|
480
|
+
format: string;
|
|
481
|
+
/**
|
|
482
|
+
* List of warnings from build plugins.
|
|
483
|
+
*/
|
|
484
|
+
logs: BuildLogs[];
|
|
485
|
+
}
|
|
486
|
+
interface BuildStats {
|
|
487
|
+
/**
|
|
488
|
+
* The root path of the project.
|
|
489
|
+
*/
|
|
490
|
+
cwd: string;
|
|
491
|
+
/**
|
|
492
|
+
* Final bundle size.
|
|
493
|
+
*/
|
|
494
|
+
size: number;
|
|
495
|
+
/**
|
|
496
|
+
* Total bundle build time.
|
|
497
|
+
*/
|
|
498
|
+
buildTime: number;
|
|
499
|
+
/**
|
|
500
|
+
* List of generated bundle modules.
|
|
501
|
+
*/
|
|
502
|
+
files: BuildEntryStats[];
|
|
503
|
+
}
|
|
504
|
+
type PickEntryChunkOptions = 'input' | 'name' | 'globals' | 'extend' | 'minify' | 'transformers';
|
|
505
|
+
type PickEntryDtsOptions = 'declaration' | 'dts' | 'transformers';
|
|
506
|
+
interface BuildEntryOptions extends EntryBase, Pick<EntryChunk, PickEntryChunkOptions>, Pick<EntryDeclaration, PickEntryDtsOptions> {
|
|
507
|
+
/**
|
|
508
|
+
* Specifies the path of the transformed file.
|
|
509
|
+
*
|
|
510
|
+
* @default undefined
|
|
511
|
+
*/
|
|
512
|
+
output?: string;
|
|
513
|
+
/**
|
|
514
|
+
* Specifies options for default plugins.
|
|
515
|
+
*
|
|
516
|
+
* @default undefined
|
|
517
|
+
*/
|
|
518
|
+
transformers?: TransformersChunk & TransformersDeclaration;
|
|
519
|
+
/**
|
|
520
|
+
* Specifies list of default plugins.
|
|
521
|
+
*/
|
|
522
|
+
defaultPlugins: Plugin[];
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
interface HooksOptions {
|
|
526
|
+
/**
|
|
527
|
+
* Called at the beginning of bundling.
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
*
|
|
531
|
+
* ```ts
|
|
532
|
+
* export default defineConfig({
|
|
533
|
+
* hooks: {
|
|
534
|
+
* 'bundle:start': async (options) => {
|
|
535
|
+
* // ...
|
|
536
|
+
* }
|
|
537
|
+
* }
|
|
538
|
+
* })
|
|
539
|
+
* ```
|
|
540
|
+
*
|
|
541
|
+
* @default undefined
|
|
542
|
+
*/
|
|
543
|
+
'bundle:start'?: (options: Options) => void | Promise<void>;
|
|
544
|
+
/**
|
|
545
|
+
* Called at the beginning of building.
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
*
|
|
549
|
+
* ```ts
|
|
550
|
+
* export default defineConfig({
|
|
551
|
+
* hooks: {
|
|
552
|
+
* 'build:start': async (options, stats) => {
|
|
553
|
+
* // ...
|
|
554
|
+
* }
|
|
555
|
+
* }
|
|
556
|
+
* })
|
|
557
|
+
* ```
|
|
558
|
+
*
|
|
559
|
+
* @default undefined
|
|
560
|
+
*/
|
|
561
|
+
'build:start'?: (options: Options, stats: BuildStats) => void | Promise<void>;
|
|
562
|
+
/**
|
|
563
|
+
* Called on each entry just before the build process.
|
|
564
|
+
*
|
|
565
|
+
* Provides the ability to customize entry options before they are passed to the next phase.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
*
|
|
569
|
+
* ```ts
|
|
570
|
+
* export default defineConfig({
|
|
571
|
+
* hooks: {
|
|
572
|
+
* 'build:entry:start': async (entry, stats) => {
|
|
573
|
+
* // ...
|
|
574
|
+
* }
|
|
575
|
+
* }
|
|
576
|
+
* })
|
|
577
|
+
* ```
|
|
578
|
+
*
|
|
579
|
+
* @default undefined
|
|
580
|
+
*/
|
|
581
|
+
'build:entry:start'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
|
|
582
|
+
/**
|
|
583
|
+
* Called on each entry right after the build process is completed.
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
*
|
|
587
|
+
* ```ts
|
|
588
|
+
* export default defineConfig({
|
|
589
|
+
* hooks: {
|
|
590
|
+
* 'build:entry:end': async (entry, stats) => {
|
|
591
|
+
* // ...
|
|
592
|
+
* }
|
|
593
|
+
* }
|
|
594
|
+
* })
|
|
595
|
+
* ```
|
|
596
|
+
*
|
|
597
|
+
* @default undefined
|
|
598
|
+
*/
|
|
599
|
+
'build:entry:end'?: (entry: BuildEntryOptions, stats: BuildEntryStats) => void | Promise<void>;
|
|
600
|
+
/**
|
|
601
|
+
* Called right after building is complete.
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
*
|
|
605
|
+
* ```ts
|
|
606
|
+
* export default defineConfig({
|
|
607
|
+
* hooks: {
|
|
608
|
+
* 'build:end': async (options, stats) => {
|
|
609
|
+
* // ...
|
|
610
|
+
* }
|
|
611
|
+
* }
|
|
612
|
+
* })
|
|
613
|
+
* ```
|
|
614
|
+
*
|
|
615
|
+
* @default undefined
|
|
616
|
+
*/
|
|
617
|
+
'build:end'?: (options: Options, stats: BuildStats) => void | Promise<void>;
|
|
618
|
+
/**
|
|
619
|
+
* Called right after bundling is complete.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
*
|
|
623
|
+
* ```ts
|
|
624
|
+
* export default defineConfig({
|
|
625
|
+
* hooks: {
|
|
626
|
+
* 'bundle:end': async (options) => {
|
|
627
|
+
* // ...
|
|
628
|
+
* }
|
|
629
|
+
* }
|
|
630
|
+
* })
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* @default undefined
|
|
634
|
+
*/
|
|
635
|
+
'bundle:end'?: (options: Options) => void | Promise<void>;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
interface ConfigLoader {
|
|
639
|
+
options: Options;
|
|
640
|
+
path: string;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* List of global defaults for externals.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
*
|
|
648
|
+
* ```ts
|
|
649
|
+
* import { externals } from '@hypernym/bundler'
|
|
650
|
+
*
|
|
651
|
+
* export default defineConfig({
|
|
652
|
+
* entries: [
|
|
653
|
+
* {
|
|
654
|
+
* input: './src/index.ts',
|
|
655
|
+
* externals: [...externals, 'id', /regexp/]
|
|
656
|
+
* },
|
|
657
|
+
* ]
|
|
658
|
+
* })
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
declare const externals: RegExp[];
|
|
662
|
+
/**
|
|
663
|
+
* `Hyperbundler` automatically detects custom configuration from the project root that can override or extend the build behavior.
|
|
664
|
+
*
|
|
665
|
+
* Configuration file also accepts `.js`, `.mjs`, `.ts`, `.mts` formats.
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
*
|
|
669
|
+
* ```ts
|
|
670
|
+
* import { defineConfig } from '@hypernym/bundler'
|
|
671
|
+
*
|
|
672
|
+
* export default defineConfig({
|
|
673
|
+
* // ...
|
|
674
|
+
* })
|
|
675
|
+
* ```
|
|
676
|
+
*/
|
|
677
|
+
declare function defineConfig(options: Options): Options;
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Resolves external module IDs into custom paths.
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
*
|
|
684
|
+
* ```ts
|
|
685
|
+
* import { defineConfig, resolvePaths } from '@hypernym/bundler'
|
|
686
|
+
*
|
|
687
|
+
* export default defineConfig({
|
|
688
|
+
* entries: [
|
|
689
|
+
* {
|
|
690
|
+
* input: './src/index.ts',
|
|
691
|
+
* externals: [/^@\/path/],
|
|
692
|
+
* paths: resolvePaths([
|
|
693
|
+
* // replaces `@/path` with `./path/index.mjs`
|
|
694
|
+
* { find: /^@\/path/, replacement: './path/index.mjs', }
|
|
695
|
+
* ]),
|
|
696
|
+
* },
|
|
697
|
+
* ]
|
|
698
|
+
* })
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
declare function resolvePaths(options: ResolvePathsOptions[]): (id: string) => string;
|
|
702
|
+
|
|
703
|
+
interface ResolvePathsOptions {
|
|
704
|
+
find: string | RegExp;
|
|
705
|
+
replacement: string;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
export { type BuildLogs, type BuildStats, type ConfigLoader, type CopyOptions, type EntryBase, type EntryChunk, type EntryCopy, type EntryDeclaration, type EntryOptions, type EntryTemplate, type HooksOptions, type Options, type ResolvePathsOptions, type TransformersChunk, type TransformersDeclaration, defineConfig, externals, resolvePaths };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypernym/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"author": "Hypernym Studio",
|
|
5
5
|
"description": "ESM & TS module bundler.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
"homepage": "https://github.com/hypernym-studio/bundler",
|
|
9
9
|
"funding": "https://github.com/sponsors/ivodolenc",
|
|
10
10
|
"type": "module",
|
|
11
|
-
"types": "./dist/types/index.d.
|
|
11
|
+
"types": "./dist/types/index.d.cts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"types": "./dist/types/index.d.
|
|
15
|
-
"import": "./dist/index.mjs"
|
|
14
|
+
"types": "./dist/types/index.d.mts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
@@ -67,9 +68,9 @@
|
|
|
67
68
|
"@hypernym/utils": "^3.4.0",
|
|
68
69
|
"@rollup/plugin-alias": "^5.1.1",
|
|
69
70
|
"@rollup/plugin-json": "^6.1.0",
|
|
70
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
71
|
-
"@rollup/plugin-replace": "^
|
|
72
|
-
"@rollup/pluginutils": "^5.1.
|
|
71
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
72
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
73
|
+
"@rollup/pluginutils": "^5.1.2",
|
|
73
74
|
"esbuild": "^0.24.0",
|
|
74
75
|
"rollup": "^4.22.4",
|
|
75
76
|
"rollup-plugin-dts": "^6.1.1"
|
|
@@ -78,8 +79,8 @@
|
|
|
78
79
|
"@hypernym/eslint-config": "^3.5.0",
|
|
79
80
|
"@hypernym/prettier-config": "^3.2.0",
|
|
80
81
|
"@hypernym/tsconfig": "^2.4.0",
|
|
81
|
-
"@types/node": "^22.
|
|
82
|
-
"eslint": "^9.11.
|
|
82
|
+
"@types/node": "^22.6.1",
|
|
83
|
+
"eslint": "^9.11.1",
|
|
83
84
|
"prettier": "^3.3.3",
|
|
84
85
|
"typescript": "^5.5.4"
|
|
85
86
|
}
|