Skip to content

Commit a50ed93

Browse files
fix(dev): re-enable manifestLoaderPlugin after child builds are done (#234)
Co-authored-by: Aaron <[email protected]>
1 parent 7aaba64 commit a50ed93

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

packages/vite-plugin-web-extension/src/build/build-context.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,35 @@ export function createBuildContext({
154154
// Print configs deep enough to include rollup inputs
155155
logger.verbose("Final configs: " + inspect(buildConfigs, undefined, 7));
156156

157-
for (const config of buildConfigs) {
158-
const bundleTracker = bundleTrackerPlugin();
159-
(config.plugins ??= []).push(bundleTracker);
160-
161-
const output = await vite.build(config);
162-
if ("on" in output) {
163-
activeWatchers.push(output);
164-
// In watch mode, wait until it's built once
165-
await waitForWatchBuildComplete(output);
166-
}
157+
process.env.VITE_PLUGIN_WEB_EXTENSION_CHILD_BUILD = "true";
158+
try {
159+
for (const config of buildConfigs) {
160+
const bundleTracker = bundleTrackerPlugin();
161+
(config.plugins ??= []).push(bundleTracker);
162+
163+
const output = await vite.build(config);
164+
if ("on" in output) {
165+
activeWatchers.push(output);
166+
// In watch mode, wait until it's built once
167+
await waitForWatchBuildComplete(output);
168+
}
167169

168-
// Save the bundle chunks
169-
const input = config.build?.lib ?? config.build?.rollupOptions?.input;
170-
if (input) {
171-
const chunks = bundleTracker.getChunks() ?? [];
172-
for (const file of getInputPaths(paths, input)) {
173-
bundles[file] = chunks;
170+
// Save the bundle chunks
171+
const input = config.build?.lib ?? config.build?.rollupOptions?.input;
172+
if (input) {
173+
const chunks = bundleTracker.getChunks() ?? [];
174+
for (const file of getInputPaths(paths, input)) {
175+
bundles[file] = chunks;
176+
}
174177
}
175178
}
176-
}
177-
// This prints before the manifest plugin continues in build mode
178-
if (mode === BuildMode.BUILD) {
179-
printCompleted();
179+
// This prints before the manifest plugin continues in build mode
180+
if (mode === BuildMode.BUILD) {
181+
printCompleted();
182+
}
183+
} finally {
184+
// Allow the parent build to rerun its config file (i.e. for a dev server restart)
185+
process.env.VITE_PLUGIN_WEB_EXTENSION_CHILD_BUILD = "";
180186
}
181187
},
182188
getBundles() {

packages/vite-plugin-web-extension/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export default function webExtension(
1212
if (process.env.VITE_PLUGIN_WEB_EXTENSION_CHILD_BUILD === "true") {
1313
return [];
1414
}
15-
process.env.VITE_PLUGIN_WEB_EXTENSION_CHILD_BUILD = "true";
1615

1716
const internalOptions: ResolvedOptions = {
1817
additionalInputs: options.additionalInputs ?? [],

0 commit comments

Comments
 (0)