@hypernym/bundler 0.10.0 → 0.12.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
@@ -1,22 +1,36 @@
1
- # @hypernym/bundler
1
+ <h1 align="center">Hyperbundler</h1>
2
2
 
3
- ESM & TS module bundler.
3
+ <p align="center">ESM & TS module bundler.</p>
4
4
 
5
- <sub><a href="https://github.com/hypernym-studio/bundler">Repository</a> | <a href="https://www.npmjs.com/package/@hypernym/bundler">Package</a> | <a href="https://github.com/hypernym-studio/bundler/releases">Releases</a> | <a href="https://github.com/hypernym-studio/bundler/discussions">Discussions</a></sub>
5
+ <p align="center">
6
+ <a href="https://github.com/hypernym-studio/bundler">Repository</a>
7
+ <span>+</span>
8
+ <a href="https://www.npmjs.com/package/@hypernym/bundler">Package</a>
9
+ <span>+</span>
10
+ <a href="https://github.com/hypernym-studio/bundler/releases">Releases</a>
11
+ <span>+</span>
12
+ <a href="https://github.com/hypernym-studio/bundler/discussions">Discussions</a>
13
+ </p>
6
14
 
7
- ```sh
8
- pnpm add -D @hypernym/bundler
9
- ```
15
+ <pre align="center">pnpm add -D @hypernym/bundler</pre>
16
+
17
+ <p align="center">
18
+ <strong>Hypernym Studio</strong>
19
+ </p>
20
+
21
+ <br>
10
22
 
11
23
  ## Features
12
24
 
13
25
  - Powered by Rollup
26
+ - Written in TypeScript
14
27
  - Allows advanced customization
15
28
  - Provides a powerful hooking system
16
29
  - Supports all TS module resolutions
17
30
  - Exports fully optimized code
18
31
  - Follows modern practice
19
32
  - Super easy to use
33
+ - API friendly
20
34
 
21
35
  ## Quick Start
22
36
 
@@ -38,6 +52,8 @@ export default defineConfig({
38
52
 
39
53
  2. Specify the bundle's entry points:
40
54
 
55
+ > See all [options](./src/types/options.ts).
56
+
41
57
  ```ts
42
58
  // bundler.config.ts
43
59
 
@@ -46,10 +62,11 @@ import { defineConfig } from '@hypernym/bundler'
46
62
  export default defineConfig({
47
63
  entries: [
48
64
  { input: './src/index.ts' },
49
- { types: './src/types/index.ts' },
65
+ { declaration: './src/types/index.ts' },
50
66
  {
51
67
  input: './src/utils/index.ts',
52
- plugins: {
68
+ output: './dist/utils/utils.min.mjs',
69
+ transformers: {
53
70
  esbuild: { minify: true },
54
71
  },
55
72
  },
@@ -64,6 +81,219 @@ export default defineConfig({
64
81
  npx hyperbundler
65
82
  ```
66
83
 
84
+ <details>
85
+ <summary>CLI Output</summary>
86
+
87
+ <br>
88
+ <p>Example of CLI Output:</p>
89
+
90
+ ```txt
91
+ ┌─────────────────┐
92
+ │ ✦✦ HYPERBUNDLER │ v0.11.0
93
+ └─────────────────┘
94
+ i Config bundler.config.ts
95
+ i Bundling started...
96
+ * Processing [8:07:26 PM] Transforming files
97
+
98
+ ├─ + esm ./dist/index.mjs (50ms) 313 B
99
+ ├─ + dts ./dist/types/index.d.ts (1.23s) 13.61 KB
100
+ ├─ + esm ./dist/bin/index.mjs (119ms) 16.53 KB
101
+
102
+ * Succeeded [8:07:28 PM] Module transformation is done
103
+ ✔ Bundling fully completed in 1.40s
104
+ ✔ 3 modules transformed. Total size is 30.45 KB
105
+ ✦✦ HYPERBUNDLER [8:07:28 PM] Bundle is generated and ready for production
106
+ ```
107
+
108
+ </details>
109
+
110
+ ## Options
111
+
112
+ All options are documented with descriptions and examples, and auto-completion will be offered as you type.
113
+
114
+ Simply hover over the property and see what it does in the `quickinfo`.
115
+
116
+ ### entries
117
+
118
+ - Type: `EntryOptions[]`
119
+
120
+ Specifies the bundle's entry points.
121
+
122
+ It allows you to manually set all build entries and adjust options for each one individually.
123
+
124
+ ```ts
125
+ // bundler.config.ts
126
+
127
+ import { defineConfig } from '@hypernym/bundler'
128
+
129
+ export default defineConfig({
130
+ entries: [
131
+ { input: './src/index.ts' }, // => './dist/index.mjs'
132
+ { declaration: './src/types.ts' }, // => './dist/types.d.ts'
133
+ // ...
134
+ ],
135
+ })
136
+ ```
137
+
138
+ #### Entry Chunk
139
+
140
+ - [Types](./src/types/entries.ts)
141
+
142
+ Automatically transforms `chunks` for production.
143
+
144
+ ```ts
145
+ // bundler.config.ts
146
+
147
+ import { defineConfig } from '@hypernym/bundler'
148
+
149
+ export default defineConfig({
150
+ entries: [
151
+ {
152
+ input: './src/index.ts', // => './dist/index.mjs'
153
+ },
154
+ ],
155
+ })
156
+ ```
157
+
158
+ #### Entry Declaration
159
+
160
+ - [Types](./src/types/entries.ts)
161
+
162
+ Builds TypeScript `declaration` files (.d.ts) for production.
163
+
164
+ ```ts
165
+ // bundler.config.ts
166
+
167
+ import { defineConfig } from '@hypernym/bundler'
168
+
169
+ export default defineConfig({
170
+ entries: [
171
+ {
172
+ { declaration: './src/types.ts' }, // => './dist/types.d.ts'
173
+ },
174
+ ],
175
+ })
176
+ ```
177
+
178
+ #### Entry Copy
179
+
180
+ - [Types](./src/types/entries.ts)
181
+
182
+ Copies the single `file` or entire `directory` structure from source to destination, including subdirectories and files.
183
+
184
+ This can be very useful for copying some assets that don't need a transformation process, but a simple copy paste feature.
185
+
186
+ ```ts
187
+ // bundler.config.ts
188
+
189
+ import { defineConfig } from '@hypernym/bundler'
190
+
191
+ export default defineConfig({
192
+ entries: [
193
+ {
194
+ copy: {
195
+ input: './src/path/file.ts', // or ['path-dir', 'path-file.ts', ...]
196
+ output: './dist/out', // path to output dir
197
+ },
198
+ },
199
+ ],
200
+ })
201
+ ```
202
+
203
+ #### Entry Template
204
+
205
+ - [Types](./src/types/entries.ts)
206
+
207
+ Provides the ability to dynamically inject `template` content during the build phase and writes the file to the destination path defined in the output property.
208
+
209
+ ```ts
210
+ // bundler.config.ts
211
+
212
+ import { defineConfig } from '@hypernym/bundler'
213
+ import { name, version } from './package.json'
214
+
215
+ export default defineConfig({
216
+ entries: [
217
+ {
218
+ template: `// Package ${name} v${version} ...`,
219
+ output: './dist/template.ts',
220
+ },
221
+ ],
222
+ })
223
+ ```
224
+
225
+ ### outDir
226
+
227
+ - Type: `string`
228
+ - Default: `dist`
229
+
230
+ Specifies the output directory for production bundle.
231
+
232
+ ```ts
233
+ // bundler.config.ts
234
+
235
+ import { defineConfig } from '@hypernym/bundler'
236
+
237
+ export default defineConfig({
238
+ outDir: 'output',
239
+ })
240
+ ```
241
+
242
+ ### externals
243
+
244
+ - Type: `(string | RegExp)[]`
245
+ - Default: `[/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]`
246
+
247
+ Specifies the module IDs, or regular expressions to match module IDs, that should remain external to the bundle.
248
+
249
+ IDs and regexps from this option are applied globally to all entries.
250
+
251
+ Also, it is possible to define externals individually per entry (`entry.externals`).
252
+
253
+ ```ts
254
+ // bundler.config.ts
255
+
256
+ import { defineConfig } from '@hypernym/bundler'
257
+
258
+ export default defineConfig({
259
+ externals: ['id-1', 'id-2', /regexp/],
260
+ })
261
+ ```
262
+
263
+ ### alias
264
+
265
+ - Type: `{ find: string | RegExp; replacement: string; }[]`
266
+ - Default: `undefined`
267
+
268
+ Specifies prefixes that will resolve imports with custom paths.
269
+
270
+ Enables these `alias` by default:
271
+
272
+ ```ts
273
+ // Imports module from './src/utils/index.js'
274
+ import { module } from '@/utils' // @
275
+ import { module } from '~/utils' // ~
276
+ ```
277
+
278
+ Also, it is possible to completely override the default aliases by setting custom ones.
279
+
280
+ ```ts
281
+ // bundler.config.ts
282
+
283
+ import { defineConfig } from '@hypernym/bundler'
284
+
285
+ export default defineConfig({
286
+ alias: [{ find: /^#/, replacement: resolve('./src') }],
287
+ })
288
+ ```
289
+
290
+ Now imports can be used like this:
291
+
292
+ ```ts
293
+ // Imports module from './src/utils/index.js'
294
+ import { module } from '#/utils' // #
295
+ ```
296
+
67
297
  ## Hooks
68
298
 
69
299
  List of lifecycle hooks that are called at various phases:
@@ -132,26 +362,19 @@ Provides the ability to customize entry options before they are passed to the ne
132
362
  // bundler.config.ts
133
363
 
134
364
  import { defineConfig } from '@hypernym/bundler'
135
- import { plugin1, plugin2, plugin3 } from './src/utils/plugins.js'
365
+ import { plugin1, plugin2 } from './src/utils/plugins.js'
136
366
 
137
367
  export default defineConfig({
138
368
  hooks: {
139
369
  'build:entry:start': async (options, stats) => {
140
370
  // adds custom plugins for a specific entry only
141
371
  if (options.input?.includes('./src/index.ts')) {
142
- options.plugins = [
372
+ options.defaultPlugins = [
143
373
  plugin1(), // adds a custom plugin before the default bundler plugins
144
- ...options.plugins, // list of default bundler plugins
374
+ ...options.defaultPlugins, // list of default bundler plugins
145
375
  plugin2(), // adds a custom plugin after the default bundler plugins
146
376
  ]
147
377
  }
148
- // adds custom plugins for a specific types only
149
- if (options.types?.includes('./src/types.ts')) {
150
- options.plugins = [
151
- ...options.plugins, // list of default bundler plugins
152
- plugin3(), // adds a custom plugin designed to work only with TS declarations
153
- ]
154
- }
155
378
  },
156
379
  },
157
380
  })
@@ -220,99 +443,26 @@ export default defineConfig({
220
443
  })
221
444
  ```
222
445
 
223
- ## Options
224
-
225
- ### outDir
226
-
227
- - Type: `string`
228
- - Default: `dist`
229
-
230
- Specifies the output directory for production bundle.
231
-
232
- ```ts
233
- // bundler.config.ts
234
-
235
- import { defineConfig } from '@hypernym/bundler'
236
-
237
- export default defineConfig({
238
- outDir: 'output',
239
- })
240
- ```
241
-
242
- ### externals
243
-
244
- - Type: `(string | RegExp)[]`
245
- - Default: `[/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]`
246
-
247
- Specifies the module IDs, or regular expressions to match module IDs, that should remain external to the bundle.
248
-
249
- IDs and regexps from this option are applied globally to all entries.
250
-
251
- Also, it is possible to define externals individually per entry (`entry.externals`).
252
-
253
- ```ts
254
- // bundler.config.ts
255
-
256
- import { defineConfig } from '@hypernym/bundler'
257
-
258
- export default defineConfig({
259
- externals: ['id-1', 'id-2', /regexp/],
260
- })
261
- ```
262
-
263
- ### alias
264
-
265
- - Type: `true`
266
- - Default: `undefined`
267
-
268
- Specifies global path alias support.
269
-
270
- If true, it enables import prefixes:
271
-
272
- - `@/*`
273
- - `~/*`
274
-
275
- ```ts
276
- // bundler.config.ts
277
-
278
- import { defineConfig } from '@hypernym/bundler'
279
-
280
- export default defineConfig({
281
- alias: true,
282
- })
283
- ```
284
-
285
- After that it can be imported as:
286
-
287
- ```ts
288
- // Imports module from './src/utils/index.js'
289
- import { module } from '@/utils'
290
-
291
- // or
292
-
293
- // Imports module from './src/utils/index.js'
294
- import { module } from '~/utils'
295
- ```
296
-
297
446
  ## Utils
298
447
 
299
- ### replacePath
448
+ ### resolvePaths
300
449
 
301
- - Type: `(path: RegExp | string, replace: string): (id: string) => string`
450
+ - Type: `(options: ResolvePathsOptions[]): (id: string) => string`
302
451
 
303
- Replaces the external module ID with a custom value.
452
+ Resolves external module IDs into custom paths.
304
453
 
305
454
  ```ts
306
- import { defineConfig, replacePath } from '@hypernym/bundler'
455
+ import { defineConfig, resolvePaths } from '@hypernym/bundler'
307
456
 
308
457
  export default defineConfig({
309
458
  entries: [
310
459
  {
311
460
  input: './src/index.ts',
312
- output: './dist/index.mjs',
313
461
  externals: [/^@\/path/],
314
- // replaces `@/path` with `./path/index.mjs`
315
- paths: (id) => replacePath(/^@\/path/, './easing/index.mjs')(id),
462
+ paths: resolvePaths([
463
+ // replaces `@/path` with `./path/index.mjs`
464
+ { find: /^@\/path/, replacement: './path/index.mjs' },
465
+ ]),
316
466
  },
317
467
  ],
318
468
  })
@@ -325,7 +475,7 @@ export default defineConfig({
325
475
  Set a custom config path via the CLI command:
326
476
 
327
477
  ```sh
328
- npx hyperbundler --config my.config.js
478
+ npx hyperbundler --config hyper.config.ts
329
479
  ```
330
480
 
331
481
  ## Community