Skip to content

Commit

Permalink
feat: update types and add new entry hooks (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivodolenc authored Oct 19, 2023
1 parent 037e39c commit 2da9e83
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 111 deletions.
181 changes: 181 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,162 @@ export default defineConfig({
npx hyperbundler
```
## Hooks
List of lifecycle hooks that are called at various phases:
| Name | Description |
| --------------------------------------- | ---------------------------------------------------------------- |
| [`bundle:start`](#bundlestart) | Called at the beginning of bundling. |
| [`build:start`](#buildstart) | Called at the beginning of building. |
| [`build:entry:start`](#buildentrystart) | Called on each entry just before the build process. |
| [`build:entry:end`](#buildentryend) | Called on each entry right after the build process is completed. |
| [`build:end`](#buildend) | Called right after building is complete. |
| [`bundle:end`](#bundleend) | Called right after bundling is complete. |
### bundle:start
- Type: `(options: Options) => void | Promise<void>`
- Default: `undefined`
Called at the beginning of bundling.
```ts
// bundler.config.ts
import { defineConfig } from '@hypernym/bundler'

export default defineConfig({
hooks: {
'bundle:start': async (options) => {
// ...
},
},
})
```
### build:start
- Type: `(options: Options, stats: BuildStats) => void | Promise<void>`
- Default: `undefined`
Called at the beginning of building.
```ts
// bundler.config.ts

import { defineConfig } from '@hypernym/bundler'

export default defineConfig({
hooks: {
'build:start': async (options, stats) => {
// ...
},
},
})
```
### build:entry:start
- Type: `(options: BuildEntryOptions, stats: BuildStats) => void | Promise<void>`
- Default: `undefined`
Called on each entry just before the build process.
Provides the ability to customize entry options before they are passed to the next phase.
```ts
// bundler.config.ts

import { defineConfig } from '@hypernym/bundler'
import { plugin1, plugin2, plugin3 } from './src/utils/plugins.js'

export default defineConfig({
hooks: {
'build:entry:start': async (options, stats) => {
// adds custom plugins for a specific entry only
if (options.input?.includes('./src/index.ts')) {
options.plugins = [
plugin1(), // adds a custom plugin before the default bundler plugins
...options.plugins, // list of default bundler plugins
plugin2(), // adds a custom plugin after the default bundler plugins
]
}
// adds custom plugins for a specific types only
if (options.types?.includes('./src/types.ts')) {
options.plugins = [
...options.plugins, // list of default bundler plugins
plugin3(), // adds a custom plugin designed to work only with TS declarations
]
}
},
},
})
```
### build:entry:end
- Type: `(options: BuildEntryOptions, stats: BuildStats) => void | Promise<void>`
- Default: `undefined`
Called on each entry right after the build process is completed.
```ts
// bundler.config.ts

import { defineConfig } from '@hypernym/bundler'

export default defineConfig({
hooks: {
'build:entry:end': async (options, stats) => {
// ...
},
},
})
```
### build:end
- Type: `(options: Options, stats: BuildStats) => void | Promise<void>`
- Default: `undefined`
Called right after building is complete.
```ts
// bundler.config.ts

import { defineConfig } from '@hypernym/bundler'

export default defineConfig({
hooks: {
'build:end': async (options, stats) => {
// ...
},
},
})
```
### bundle:end
- Type: `(options: Options) => void | Promise<void>`
- Default: `undefined`
Called right after bundling is complete.
```ts
// bundler.config.ts

import { defineConfig } from '@hypernym/bundler'

export default defineConfig({
hooks: {
'bundle:end': async (options) => {
// ...
},
},
})
```
## Options
### outDir
Expand All @@ -74,11 +230,36 @@ Specifies the output directory for production bundle.
```ts
// bundler.config.ts

import { defineConfig } from '@hypernym/bundler'

export default defineConfig({
outDir: 'output',
})
```
### externals
- Type: `(string | RegExp)[]`
- Default: `[/^node:/, /^@types/, /^@rollup/, /^@hypernym/, /^rollup/, ...pkg.dependencies]`
Specifies the module IDs, or regular expressions to match module IDs, that should remain external to the bundle.
IDs and regexps from this option are applied globally to all entries.
Also, it is possible to define externals individually per entry (`entry.externals`).
```ts
// bundler.config.ts

import { defineConfig } from '@hypernym/bundler'

export default defineConfig({
externals: ['id-1', 'id-2', /regexp/],
})
```
## CLI
### Custom Config
Set a custom config path via the CLI command:
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@hypernym/eslint-config": "^2.0.2",
"@hypernym/prettier-config": "^2.0.2",
"@hypernym/tsconfig": "^1.1.0",
"@types/node": "^20.8.6",
"@types/node": "^20.8.7",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"tsx": "^3.14.0",
Expand Down
Loading

0 comments on commit 2da9e83

Please sign in to comment.