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