Skip to content

Commit 8c7f184

Browse files
committed
docs: correct the externalsForTarget contract and document installedPackagesForTarget
externalsForTarget is synchronous; the example showed async, which the build consumes incorrectly and TypeScript rejects. Adds a section for the new diagnostics-only installedPackagesForTarget hook.
1 parent cc36ea8 commit 8c7f184

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

docs/config/extensions/custom.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default defineConfig({
8080
extensions: [
8181
{
8282
name: "my-extension",
83-
externalsForTarget: async (target) => {
83+
externalsForTarget: (target) => {
8484
return ["my-dependency"];
8585
},
8686
},
@@ -89,6 +89,19 @@ export default defineConfig({
8989
});
9090
```
9191

92+
### installedPackagesForTarget
93+
94+
This tells build diagnostics which packages your extension installs into the deployed image for a given target, so warnings (like the one for packages loaded via `createRequire()`) don't fire for packages that will actually be available at runtime. The bundler ignores this hook, so declaring it never changes the build output. Return an empty array to declare that your extension installs no packages, which keeps those diagnostics active in `dev` for projects using your extension.
95+
96+
```ts
97+
{
98+
name: "my-extension",
99+
installedPackagesForTarget: (target) => {
100+
return target === "deploy" ? ["my-dependency"] : [];
101+
},
102+
}
103+
```
104+
92105
### onBuildStart
93106

94107
This hook runs before the build starts. It receives the `BuildContext` object as an argument.

0 commit comments

Comments
 (0)