@@ -25,7 +25,7 @@ import { ViteNodeServer } from 'vite-node/server';
2525import { ViteNodeRunner } from 'vite-node/client' ;
2626import { installSourcemapsSupport } from 'vite-node/source-map' ;
2727import { createExtensionEnvironment } from '../../utils/environments' ;
28- import { relative , join , extname , dirname } from 'node:path' ;
28+ import { dirname , extname , join , relative } from 'node:path' ;
2929import fs from 'fs-extra' ;
3030import { normalizePath } from '../../utils/paths' ;
3131
@@ -109,24 +109,25 @@ export async function createViteBuilder(
109109 const plugins : NonNullable < vite . UserConfig [ 'plugins' ] > = [
110110 wxtPlugins . entrypointGroupGlobals ( entrypoint ) ,
111111 ] ;
112+ const iifeReturnValueName = safeVarName ( entrypoint . name ) ;
113+
112114 if (
113115 entrypoint . type === 'content-script-style' ||
114116 entrypoint . type === 'unlisted-style'
115117 ) {
116118 plugins . push ( wxtPlugins . cssEntrypoints ( entrypoint , wxtConfig ) ) ;
117119 }
118120
119- const iifeReturnValueName = safeVarName ( entrypoint . name ) ;
120- const libMode : vite . UserConfig = {
121+ if (
122+ entrypoint . type === 'content-script' ||
123+ entrypoint . type === 'unlisted-script'
124+ ) {
125+ plugins . push ( wxtPlugins . iifeFooter ( iifeReturnValueName ) ) ;
126+ }
127+
128+ return {
121129 mode : wxtConfig . mode ,
122130 plugins,
123- esbuild : {
124- // Add a footer with the returned value so it can return values to `scripting.executeScript`
125- // Footer is added a part of esbuild to make sure it's not minified. It
126- // get's removed if added to `build.rollupOptions.output.footer`
127- // See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
128- footer : iifeReturnValueName + ';' ,
129- } ,
130131 build : {
131132 lib : {
132133 entry,
@@ -162,8 +163,7 @@ export async function createViteBuilder(
162163 // See https://github.com/aklinker1/vite-plugin-web-extension/issues/96
163164 'process.env.NODE_ENV' : JSON . stringify ( wxtConfig . mode ) ,
164165 } ,
165- } ;
166- return libMode ;
166+ } satisfies vite . UserConfig ;
167167 } ;
168168
169169 /**
0 commit comments