@@ -25,7 +25,7 @@ import { ViteNodeServer } from 'vite-node/server';
25
25
import { ViteNodeRunner } from 'vite-node/client' ;
26
26
import { installSourcemapsSupport } from 'vite-node/source-map' ;
27
27
import { createExtensionEnvironment } from '../../utils/environments' ;
28
- import { relative , join , extname , dirname } from 'node:path' ;
28
+ import { dirname , extname , join , relative } from 'node:path' ;
29
29
import fs from 'fs-extra' ;
30
30
import { normalizePath } from '../../utils/paths' ;
31
31
@@ -109,24 +109,25 @@ export async function createViteBuilder(
109
109
const plugins : NonNullable < vite . UserConfig [ 'plugins' ] > = [
110
110
wxtPlugins . entrypointGroupGlobals ( entrypoint ) ,
111
111
] ;
112
+ const iifeReturnValueName = safeVarName ( entrypoint . name ) ;
113
+
112
114
if (
113
115
entrypoint . type === 'content-script-style' ||
114
116
entrypoint . type === 'unlisted-style'
115
117
) {
116
118
plugins . push ( wxtPlugins . cssEntrypoints ( entrypoint , wxtConfig ) ) ;
117
119
}
118
120
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 {
121
129
mode : wxtConfig . mode ,
122
130
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
- } ,
130
131
build : {
131
132
lib : {
132
133
entry,
@@ -162,8 +163,7 @@ export async function createViteBuilder(
162
163
// See https://github.com/aklinker1/vite-plugin-web-extension/issues/96
163
164
'process.env.NODE_ENV' : JSON . stringify ( wxtConfig . mode ) ,
164
165
} ,
165
- } ;
166
- return libMode ;
166
+ } satisfies vite . UserConfig ;
167
167
} ;
168
168
169
169
/**
0 commit comments