@@ -21,9 +21,6 @@ import {
2121import { Hookable } from 'hookable' ;
2222import { toArray } from '../../utils/arrays' ;
2323import { safeVarName } from '../../utils/strings' ;
24- import { ViteNodeServer } from 'vite-node/server' ;
25- import { ViteNodeRunner } from 'vite-node/client' ;
26- import { installSourcemapsSupport } from 'vite-node/source-map' ;
2724import { createExtensionEnvironment } from '../../utils/environments' ;
2825import { dirname , extname , join , relative } from 'node:path' ;
2926import fs from 'fs-extra' ;
@@ -71,7 +68,6 @@ export async function createViteBuilder(
7168
7269 // TODO: Remove once https://github.com/wxt-dev/wxt/pull/1411 is merged
7370 config . legacy ??= { } ;
74- // @ts -ignore: Untyped option:
7571 config . legacy . skipWebSocketTokenCheck = true ;
7672
7773 const server = getWxtDevServer ?.( ) ;
@@ -91,7 +87,7 @@ export async function createViteBuilder(
9187 ) ;
9288 if (
9389 wxtConfig . analysis . enabled &&
94- // If included, vite-node entrypoint loader will increment the
90+ // If included, entrypoint loader will increment the
9591 // bundleAnalysis's internal build index tracker, which we don't want
9692 ! baseConfigOptions ?. excludeAnalysisPlugin
9793 ) {
@@ -224,8 +220,7 @@ export async function createViteBuilder(
224220 } ,
225221 } ;
226222 } ;
227-
228- const createViteNodeImporter = async ( paths : string [ ] ) => {
223+ const createImporterConfig = async ( paths : string [ ] ) => {
229224 const baseConfig = await getBaseConfig ( {
230225 excludeAnalysisPlugin : true ,
231226 } ) ;
@@ -238,30 +233,7 @@ export async function createViteBuilder(
238233 wxtPlugins . removeEntrypointMainFunction ( wxtConfig , path ) ,
239234 ) ,
240235 } ;
241- const config = vite . mergeConfig ( baseConfig , envConfig ) ;
242- const server = await vite . createServer ( config ) ;
243- await server . pluginContainer . buildStart ( { } ) ;
244- const node = new ViteNodeServer (
245- // @ts -ignore: Some weird type error...
246- server ,
247- ) ;
248- installSourcemapsSupport ( {
249- getSourceMap : ( source ) => node . getSourceMap ( source ) ,
250- } ) ;
251- const runner = new ViteNodeRunner ( {
252- root : server . config . root ,
253- base : server . config . base ,
254- // when having the server and runner in a different context,
255- // you will need to handle the communication between them
256- // and pass to this function
257- fetchModule ( id ) {
258- return node . fetchModule ( id ) ;
259- } ,
260- resolveId ( id , importer ) {
261- return node . resolveId ( id , importer ) ;
262- } ,
263- } ) ;
264- return { runner, server } ;
236+ return vite . mergeConfig ( baseConfig , envConfig ) ;
265237 } ;
266238
267239 const requireDefaultExport = ( path : string , mod : any ) => {
@@ -284,26 +256,30 @@ export async function createViteBuilder(
284256 version : vite . version ,
285257 async importEntrypoint ( path ) {
286258 const env = createExtensionEnvironment ( ) ;
287- const { runner, server } = await createViteNodeImporter ( [ path ] ) ;
288- const res = await env . run ( ( ) => runner . executeFile ( path ) ) ;
289- await server . close ( ) ;
290- requireDefaultExport ( path , res ) ;
291- return res . default ;
259+ const importerConfig = await createImporterConfig ( [ path ] ) ;
260+
261+ const { module } = await env . run ( ( ) =>
262+ vite . runnerImport < { default : any } > ( path , importerConfig ) ,
263+ ) ;
264+ requireDefaultExport ( path , module ) ;
265+ return module . default ;
292266 } ,
293267 async importEntrypoints ( paths ) {
268+ const importerConfig = await createImporterConfig ( paths ) ;
269+
294270 const env = createExtensionEnvironment ( ) ;
295- const { runner, server } = await createViteNodeImporter ( paths ) ;
296- const res = await env . run ( ( ) =>
271+ return await env . run ( ( ) =>
297272 Promise . all (
298273 paths . map ( async ( path ) => {
299- const mod = await runner . executeFile ( path ) ;
300- requireDefaultExport ( path , mod ) ;
301- return mod . default ;
274+ const { module } = await vite . runnerImport < { default : any } > (
275+ path ,
276+ importerConfig ,
277+ ) ;
278+ requireDefaultExport ( path , module ) ;
279+ return module . default ;
302280 } ) ,
303281 ) ,
304282 ) ;
305- await server . close ( ) ;
306- return res ;
307283 } ,
308284 async build ( group ) {
309285 let entryConfig ;
0 commit comments