-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
docs: document egg bundler tooling #5909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # @eggjs/egg-bundler | ||
|
|
||
| Bundle an Egg application into a deployable CommonJS artifact. | ||
|
|
||
| The bundler is used by `egg-bin bundle` and is also available as a programmatic | ||
| API for tooling that needs to build bundles directly. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```ts | ||
| import { bundle } from '@eggjs/egg-bundler'; | ||
|
|
||
| await bundle({ | ||
| baseDir: '/path/to/app', | ||
| outputDir: './dist-bundle', | ||
| framework: 'egg', | ||
| mode: 'production', | ||
| }); | ||
| ``` | ||
|
|
||
| `outputDir` is resolved from `baseDir` when it is relative. The default manifest | ||
| path is `<baseDir>/.egg/manifest.json`. | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Description | | ||
| | --- | --- | | ||
| | `baseDir` | Application root directory. Required. | | ||
| | `outputDir` | Output directory for the bundled artifact. Required. | | ||
| | `manifestPath` | Path to `manifest.json`. Defaults to `<baseDir>/.egg/manifest.json`. | | ||
| | `framework` | Framework name or absolute path. Defaults to `egg`. | | ||
| | `mode` | Build mode, `production` or `development`. Defaults to `production`. | | ||
| | `tegg` | Enable tegg decorated file collection. Defaults to `true`. | | ||
| | `externals.force` | Package names to always keep external. | | ||
| | `externals.inline` | Package names to force inline even if auto-detected as external. | | ||
| | `pack.buildFunc` | Test hook for replacing the real `@utoo/pack` build entry. | | ||
| | `pack.rootPath` | Override the monorepo workspace root used by `@utoo/pack`. | | ||
|
|
||
|
killagu marked this conversation as resolved.
Outdated
|
||
| ## Result | ||
|
|
||
| `bundle()` resolves with: | ||
|
|
||
| | Field | Description | | ||
| | --- | --- | | ||
| | `outputDir` | Absolute output directory. | | ||
| | `files` | Sorted absolute paths for files written into the artifact. | | ||
| | `manifestPath` | Absolute path to `bundle-manifest.json`. | | ||
|
|
||
| ## Running The Bundle | ||
|
|
||
| ```bash | ||
| cd dist-bundle | ||
| node worker.js | ||
| ``` | ||
|
|
||
| The generated worker entry runs the app in Egg's single-process mode and serves | ||
| framework file discovery/module resolution from the inlined bundle map. | ||
|
|
||
| See [output-structure.md](./docs/output-structure.md) for artifact layout, | ||
| externals behavior, and current limitations. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| --- | ||
| title: Egg Bundler | ||
| type: package | ||
| summary: Bundles Egg applications into deployable CommonJS artifacts and powers the egg-bin bundle command. | ||
| source_files: | ||
| - tools/egg-bundler/src/index.ts | ||
| - tools/egg-bundler/src/lib/Bundler.ts | ||
| - tools/egg-bin/src/commands/bundle.ts | ||
| - tools/egg-bundler/docs/output-structure.md | ||
| updated_at: 2026-05-02 | ||
| status: active | ||
| --- | ||
|
|
||
| # Egg Bundler | ||
|
|
||
| `@eggjs/egg-bundler` is a developer tooling package under `tools/egg-bundler/`. | ||
| It exposes `bundle(config)` and the `Bundler` class for producing a deployable | ||
| CommonJS artifact from an Egg application. | ||
|
|
||
| ## Public Surfaces | ||
|
|
||
| - `tools/egg-bundler/src/index.ts` exports `bundle`, `Bundler`, the helper | ||
| classes, and the public config/result types. | ||
| - `tools/egg-bin/src/commands/bundle.ts` wires the package into | ||
| `egg-bin bundle`. | ||
|
|
||
| ## Bundle Flow | ||
|
|
||
| 1. `ManifestLoader` loads the app startup manifest, defaulting to | ||
| `<baseDir>/.egg/manifest.json`. | ||
| 2. `ExternalsResolver` classifies packages that should stay external. | ||
| 3. `EntryGenerator` writes a synthetic worker entry that installs the bundle | ||
| manifest/module loader before starting Egg. | ||
| 4. `PackRunner` invokes `@utoo/pack`. | ||
| 5. `Bundler` writes `bundle-manifest.json` and returns absolute output paths. | ||
|
|
||
| ## Current Behavior | ||
|
|
||
| - Relative `outputDir` values are resolved from `baseDir`. | ||
| - Default mode is `production`; `development` is also accepted. | ||
| - The generated app runs in Egg single-process mode. | ||
| - Native addons, ESM-only packages, peer dependencies, `@eggjs/*`, and | ||
| explicit `externals.force` entries are external. | ||
|
killagu marked this conversation as resolved.
Outdated
|
||
|
|
||
| Inference: because `egg-bin bundle` is now a public CLI surface, user-facing | ||
| tooling docs should mention the command and its key flags whenever this package | ||
| changes materially. | ||
|
killagu marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.