Skip to content
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

feat: Added bundleInfoJsonPath plugin option #211

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/config/plugin-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ webExtConfig?: any
```

This option allows you to pass configuration into `web-ext` when launching the browser. For more details, refer to [Browser Startup Configuration](/guide/configure-browser-startup.md).

## `bundleInfoJsonPath`

```ts
bundleInfoJsonPath?: string
```

If set, the plugin will write a JSON file containing information about the built bundles to the specified path in the output directory. This can for example be useful for dynamically injecting content scripts/styles from background scripts.
1 change: 1 addition & 0 deletions packages/vite-plugin-web-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function webExtension(
scriptViteConfig: options.scriptViteConfig,
transformManifest: options.transformManifest,
webExtConfig: options.webExtConfig,
bundleInfoJsonPath: options.bundleInfoJsonPath,
verbose: process.argv.includes("-d") || process.argv.includes("--debug"),
disableColors:
process.env.CI === "true" || process.env.DISABLE_COLORS === "true", // TODO: document env var
Expand Down
6 changes: 6 additions & 0 deletions packages/vite-plugin-web-extension/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export interface UserOptions {
* <https://github.com/mozilla/web-ext/blob/666886f40a967b515d43cf38fc9aec67ad744d89/src/program.js#L559>.
*/
webExtConfig?: any;

/**
* Output path to a JSON file containing information about the generated bundles.
*/
bundleInfoJsonPath?: string;
}

/**
Expand All @@ -109,6 +114,7 @@ export interface ResolvedOptions {
verbose: boolean;
disableColors: boolean;
webExtConfig?: any;
bundleInfoJsonPath?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ export function manifestLoaderPlugin(options: ResolvedOptions): vite.Plugin {
name: "manifest.json",
});

if (options.bundleInfoJsonPath) {
emitFile({
type: "asset",
source: JSON.stringify(ctx.getBundles()),
fileName: options.bundleInfoJsonPath,
});
}

await copyPublicDirToOutDir({ mode, paths });

// In dev mode, open up the browser immediately after the build context is finished with the
Expand Down
Loading