@@ -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 ( ) {
0 commit comments