@hypernym/bundler 0.14.3 → 0.20.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/LICENSE.txt +2 -1
- package/README.md +127 -97
- package/dist/bin/index.mjs +178 -479
- package/dist/build/index.mjs +311 -0
- package/dist/index.d.mts +654 -0
- package/dist/index.mjs +50 -17
- package/dist/plugins/index.d.mts +14 -0
- package/dist/plugins/index.mjs +37 -0
- package/package.json +30 -37
- package/dist/index.cjs +0 -26
- package/dist/types/index.d.cts +0 -708
- package/dist/types/index.d.mts +0 -708
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025 Ivo Dolenc
|
|
3
|
+
Copyright (c) 2025, Ivo Dolenc <https://github.com/ivodolenc>
|
|
4
|
+
Copyright (c) 2025, Hypernym Studio <https://github.com/hypernym-studio>
|
|
4
5
|
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<h1 align="center"
|
|
1
|
+
<h1 align="center">@hypernym/bundler</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">ESM & TS module bundler.</p>
|
|
4
4
|
|
|
@@ -20,11 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
## Features
|
|
22
22
|
|
|
23
|
-
- Powered by
|
|
24
|
-
- Written in TypeScript
|
|
23
|
+
- Powered by Rolldown
|
|
25
24
|
- Allows Advanced Customization
|
|
26
25
|
- Provides a Powerful Hooking System
|
|
27
|
-
- Supports All TS Module Resolutions
|
|
28
26
|
- Exports Fully Optimized Code
|
|
29
27
|
- Follows Modern Practice
|
|
30
28
|
- Super Easy to Use
|
|
@@ -67,9 +65,13 @@ export default defineConfig({
|
|
|
67
65
|
})
|
|
68
66
|
```
|
|
69
67
|
|
|
70
|
-
3. Build via
|
|
68
|
+
3. Build via commands:
|
|
71
69
|
|
|
72
70
|
```sh
|
|
71
|
+
# pnpm
|
|
72
|
+
pnpm hyperbundler
|
|
73
|
+
|
|
74
|
+
# npm
|
|
73
75
|
npx hyperbundler
|
|
74
76
|
```
|
|
75
77
|
|
|
@@ -94,6 +96,10 @@ export default defineConfig({
|
|
|
94
96
|
Set a custom config path via the CLI command:
|
|
95
97
|
|
|
96
98
|
```sh
|
|
99
|
+
# pnpm
|
|
100
|
+
pnpm hyperbundler --config hyper.config.ts
|
|
101
|
+
|
|
102
|
+
# npm
|
|
97
103
|
npx hyperbundler --config hyper.config.ts
|
|
98
104
|
```
|
|
99
105
|
|
|
@@ -124,7 +130,7 @@ Default transformation behaviour for all `dts` entries:
|
|
|
124
130
|
|
|
125
131
|
## Options
|
|
126
132
|
|
|
127
|
-
All options are documented with descriptions and examples so
|
|
133
|
+
All options are documented with descriptions and examples so autocompletion will be offered as you type. Simply hover over the property and see what it does in the quick info tooltip.
|
|
128
134
|
|
|
129
135
|
### entries
|
|
130
136
|
|
|
@@ -141,16 +147,14 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
141
147
|
|
|
142
148
|
export default defineConfig({
|
|
143
149
|
entries: [
|
|
144
|
-
{ input: './src/index.ts' }, //
|
|
145
|
-
{ dts: './src/types.ts' }, //
|
|
150
|
+
{ input: './src/index.ts' }, // outputs './dist/index.mjs'
|
|
151
|
+
{ dts: './src/types.ts' }, // outputs './dist/types.d.mts'
|
|
146
152
|
// ...
|
|
147
153
|
],
|
|
148
154
|
})
|
|
149
155
|
```
|
|
150
156
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
- [Types](./src/types/entries.ts)
|
|
157
|
+
### Entry Chunk
|
|
154
158
|
|
|
155
159
|
Automatically transforms `chunks` for production.
|
|
156
160
|
|
|
@@ -161,48 +165,38 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
161
165
|
|
|
162
166
|
export default defineConfig({
|
|
163
167
|
entries: [
|
|
164
|
-
{ input: './src/index.ts' }, //
|
|
168
|
+
{ input: './src/index.ts' }, // outputs './dist/index.mjs'
|
|
169
|
+
{
|
|
170
|
+
input: './src/index.ts',
|
|
171
|
+
output: './out/index.js', // outputs './out/index.js'
|
|
172
|
+
},
|
|
165
173
|
],
|
|
166
174
|
})
|
|
167
175
|
```
|
|
168
176
|
|
|
169
|
-
|
|
177
|
+
### Entry Dts
|
|
170
178
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Builds TypeScript `declaration` files (.d.ts) for production.
|
|
179
|
+
Builds TypeScript `declaration` files (`.d.mts`) for production.
|
|
174
180
|
|
|
175
181
|
```ts
|
|
176
|
-
// bundler.config.ts
|
|
177
|
-
|
|
178
182
|
import { defineConfig } from '@hypernym/bundler'
|
|
179
183
|
|
|
180
184
|
export default defineConfig({
|
|
181
185
|
entries: [
|
|
182
|
-
{
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
Also, it is possible to use `dts` alias.
|
|
188
|
-
|
|
189
|
-
```ts
|
|
190
|
-
import { defineConfig } from '@hypernym/bundler'
|
|
191
|
-
|
|
192
|
-
export default defineConfig({
|
|
193
|
-
entries: [
|
|
194
|
-
{ dts: './src/types.ts' }, // => './dist/types.d.mts'
|
|
186
|
+
{ dts: './src/types.ts' }, // outputs './dist/types.d.mts'
|
|
187
|
+
{
|
|
188
|
+
dts: './src/types.ts',
|
|
189
|
+
output: './out/types.d.ts', // outputs './out/types.d.ts'
|
|
190
|
+
},
|
|
195
191
|
],
|
|
196
192
|
})
|
|
197
193
|
```
|
|
198
194
|
|
|
199
|
-
|
|
195
|
+
### Entry Copy
|
|
200
196
|
|
|
201
|
-
|
|
197
|
+
Copies either a single `file` or an entire `directory` structure from the source to the destination, including all subdirectories and files.
|
|
202
198
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
This can be very useful for copying some assets that don't need a transformation process, but a simple copy paste feature.
|
|
199
|
+
This is especially useful for transferring assets that don't require any transformation, just a straightforward copy-paste operation.
|
|
206
200
|
|
|
207
201
|
```ts
|
|
208
202
|
// bundler.config.ts
|
|
@@ -212,20 +206,28 @@ import { defineConfig } from '@hypernym/bundler'
|
|
|
212
206
|
export default defineConfig({
|
|
213
207
|
entries: [
|
|
214
208
|
{
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
209
|
+
// copies a single file
|
|
210
|
+
copy: './src/path/file.ts', // outputs './dist/path/file.ts'
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
// copies a single file
|
|
214
|
+
copy: './src/path/file.ts',
|
|
215
|
+
output: './dist/subdir/custom-file-name.ts',
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
// copies the entire directory
|
|
219
|
+
input: './src/path/srcdir',
|
|
220
|
+
output: './dist/outdir',
|
|
219
221
|
},
|
|
220
222
|
],
|
|
221
223
|
})
|
|
222
224
|
```
|
|
223
225
|
|
|
224
|
-
|
|
226
|
+
### Entry Template
|
|
225
227
|
|
|
226
|
-
|
|
228
|
+
Specifies the content of the `template` file.
|
|
227
229
|
|
|
228
|
-
Provides the ability to dynamically inject
|
|
230
|
+
Provides the ability to dynamically inject template content during the build phase.
|
|
229
231
|
|
|
230
232
|
```ts
|
|
231
233
|
// bundler.config.ts
|
|
@@ -265,11 +267,9 @@ export default defineConfig({
|
|
|
265
267
|
- Type: `(string | RegExp)[]`
|
|
266
268
|
- Default: `[/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]`
|
|
267
269
|
|
|
268
|
-
Specifies the module IDs
|
|
270
|
+
Specifies the module IDs or regular expressions that match module IDs to be treated as external and excluded from the bundle.
|
|
269
271
|
|
|
270
|
-
IDs and
|
|
271
|
-
|
|
272
|
-
Also, it is possible to define externals individually per entry (`entry.externals`).
|
|
272
|
+
The IDs and regular expressions provided in this option are applied globally across all entries.
|
|
273
273
|
|
|
274
274
|
```ts
|
|
275
275
|
// bundler.config.ts
|
|
@@ -281,40 +281,19 @@ export default defineConfig({
|
|
|
281
281
|
})
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
- Type: `{ find: string | RegExp; replacement: string; }[]`
|
|
287
|
-
- Default: `undefined`
|
|
288
|
-
|
|
289
|
-
Specifies prefixes that will resolve imports with custom paths.
|
|
290
|
-
|
|
291
|
-
Enables these `alias` by default:
|
|
292
|
-
|
|
293
|
-
```ts
|
|
294
|
-
// Imports module from './src/utils/index.js'
|
|
295
|
-
import { module } from '@/utils' // @
|
|
296
|
-
import { module } from '~/utils' // ~
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
Also, it is possible to completely override the default aliases by setting custom ones.
|
|
284
|
+
Alternatively, externals can be defined individually for each entry using the `entry.externals` property.
|
|
300
285
|
|
|
301
286
|
```ts
|
|
302
|
-
// bundler.config.ts
|
|
303
|
-
|
|
304
|
-
import { defineConfig } from '@hypernym/bundler'
|
|
305
|
-
|
|
306
287
|
export default defineConfig({
|
|
307
|
-
|
|
288
|
+
entries: [
|
|
289
|
+
{
|
|
290
|
+
input: './src/index.ts',
|
|
291
|
+
externals: ['id-1', 'id-2', /regexp/],
|
|
292
|
+
},
|
|
293
|
+
],
|
|
308
294
|
})
|
|
309
295
|
```
|
|
310
296
|
|
|
311
|
-
Now imports can be used like this:
|
|
312
|
-
|
|
313
|
-
```ts
|
|
314
|
-
// Imports module from './src/utils/index.js'
|
|
315
|
-
import { module } from '#/utils' // #
|
|
316
|
-
```
|
|
317
|
-
|
|
318
297
|
### minify
|
|
319
298
|
|
|
320
299
|
- Type: `boolean`
|
|
@@ -332,7 +311,7 @@ export default defineConfig({
|
|
|
332
311
|
})
|
|
333
312
|
```
|
|
334
313
|
|
|
335
|
-
It can also be set per entry
|
|
314
|
+
It can also be set per entry:
|
|
336
315
|
|
|
337
316
|
```ts
|
|
338
317
|
export default defineConfig({
|
|
@@ -418,14 +397,7 @@ import { plugin1, plugin2 } from './src/utils/plugins.js'
|
|
|
418
397
|
export default defineConfig({
|
|
419
398
|
hooks: {
|
|
420
399
|
'build:entry:start': async (entry, stats) => {
|
|
421
|
-
//
|
|
422
|
-
if (entry.input?.includes('./src/index.ts')) {
|
|
423
|
-
entry.defaultPlugins = [
|
|
424
|
-
plugin1(), // adds a custom plugin before the default bundler plugins
|
|
425
|
-
...entry.defaultPlugins, // list of default bundler plugins
|
|
426
|
-
plugin2(), // adds a custom plugin after the default bundler plugins
|
|
427
|
-
]
|
|
428
|
-
}
|
|
400
|
+
// ...
|
|
429
401
|
},
|
|
430
402
|
},
|
|
431
403
|
})
|
|
@@ -496,34 +468,92 @@ export default defineConfig({
|
|
|
496
468
|
|
|
497
469
|
## Utils
|
|
498
470
|
|
|
499
|
-
###
|
|
500
|
-
|
|
501
|
-
- Type: `(options: ResolvePathsOptions[]): (id: string) => string`
|
|
471
|
+
### externals
|
|
502
472
|
|
|
503
|
-
|
|
473
|
+
List of global default patterns for external module identifiers.
|
|
504
474
|
|
|
505
475
|
```ts
|
|
506
|
-
import {
|
|
476
|
+
import { externals } from '@hypernym/bundler'
|
|
507
477
|
|
|
508
478
|
export default defineConfig({
|
|
509
479
|
entries: [
|
|
510
480
|
{
|
|
511
481
|
input: './src/index.ts',
|
|
512
|
-
externals: [
|
|
513
|
-
paths: resolvePaths([
|
|
514
|
-
// replaces `@/path` with `./path/index.mjs`
|
|
515
|
-
{ find: /^@\/path/, replacement: './path/index.mjs' },
|
|
516
|
-
]),
|
|
482
|
+
externals: [...externals, 'id', /regexp/],
|
|
517
483
|
},
|
|
518
484
|
],
|
|
519
485
|
})
|
|
520
486
|
```
|
|
521
487
|
|
|
522
|
-
##
|
|
488
|
+
## Plugins
|
|
523
489
|
|
|
524
|
-
|
|
490
|
+
Provides built-in plugins that can be used out of the box and additionally customized as needed.
|
|
525
491
|
|
|
526
|
-
|
|
492
|
+
```ts
|
|
493
|
+
import {
|
|
494
|
+
aliasPlugin,
|
|
495
|
+
jsonPlugin,
|
|
496
|
+
replacePlugin,
|
|
497
|
+
dts,
|
|
498
|
+
outputPaths,
|
|
499
|
+
//...
|
|
500
|
+
} from '@hypernym/bundler/plugins'
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
## Programmatic
|
|
504
|
+
|
|
505
|
+
### build
|
|
506
|
+
|
|
507
|
+
- Type: `function build(options: Options): Promise<BuildStats>`
|
|
508
|
+
|
|
509
|
+
```ts
|
|
510
|
+
import { build } from '@hypernym/bundler'
|
|
511
|
+
|
|
512
|
+
await build({
|
|
513
|
+
entries: [{ input: './src/index.ts' }],
|
|
514
|
+
// ...
|
|
515
|
+
})
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
## CLI
|
|
519
|
+
|
|
520
|
+
### config
|
|
521
|
+
|
|
522
|
+
Specifies the path to the `bundler` custom config file.
|
|
523
|
+
|
|
524
|
+
```sh
|
|
525
|
+
# pnpm
|
|
526
|
+
pnpm hyperbundler --config hyper.config.mjs
|
|
527
|
+
|
|
528
|
+
# npm
|
|
529
|
+
npx hyperbundler --config hyper.config.mjs
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### cwd
|
|
533
|
+
|
|
534
|
+
Specifies the path to the project root (current working directory).
|
|
535
|
+
|
|
536
|
+
```sh
|
|
537
|
+
# pnpm
|
|
538
|
+
pnpm hyperbundler --cwd ./custom-dir
|
|
539
|
+
|
|
540
|
+
# npm
|
|
541
|
+
npx hyperbundler --cwd ./custom-dir
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
### tsconfig
|
|
545
|
+
|
|
546
|
+
Specifies the path to the `tsconfig` file.
|
|
547
|
+
|
|
548
|
+
By default, if the file `tsconfig.json` exists in the project root, it will be used as the default config file.
|
|
549
|
+
|
|
550
|
+
```sh
|
|
551
|
+
# pnpm
|
|
552
|
+
pnpm hyperbundler --tsconfig tsconfig.json
|
|
553
|
+
|
|
554
|
+
# npm
|
|
555
|
+
npx hyperbundler --tsconfig tsconfig.json
|
|
556
|
+
```
|
|
527
557
|
|
|
528
558
|
## License
|
|
529
559
|
|