Skip to content

Commit 69b44c5

Browse files
authored
fix: onBundleReady called before manifest is generated in build mode (#221)
1 parent 1e7b107 commit 69b44c5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/vite-plugin-web-extension/src/plugins/manifest-loader-plugin.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ export function manifestLoaderPlugin(options: ResolvedOptions): vite.Plugin {
153153
});
154154
}
155155

156-
if (options.onBundleReady) {
156+
await copyPublicDirToOutDir({ mode, paths });
157+
158+
// Handle the onBundleReady callback in dev mode here, as writeBundle is not called in dev mode
159+
if (mode === BuildMode.DEV && options.onBundleReady) {
160+
logger.verbose("Running onBundleReady");
157161
await options.onBundleReady();
158162
}
159163

160-
await copyPublicDirToOutDir({ mode, paths });
161-
162164
// In dev mode, open up the browser immediately after the build context is finished with the
163165
// first build.
164166
if (mode === BuildMode.DEV && !options.disableAutoLaunch) {
@@ -287,6 +289,14 @@ export function manifestLoaderPlugin(options: ResolvedOptions): vite.Plugin {
287289
noInput.cleanupBundle(bundle);
288290
},
289291

292+
// Runs during: build, watch
293+
async writeBundle() {
294+
if (options.onBundleReady) {
295+
logger.verbose("Running onBundleReady");
296+
await options.onBundleReady();
297+
}
298+
},
299+
290300
// Runs during: watch, dev
291301
async watchChange(id) {
292302
if (

0 commit comments

Comments
 (0)