wxt 0.10.4 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/testing.cjs CHANGED
@@ -44,8 +44,8 @@ var import_node_path2 = __toESM(require("path"), 1);
44
44
  // src/core/utils/paths.ts
45
45
  var import_node_path = __toESM(require("path"), 1);
46
46
  var import_normalize_path = __toESM(require("normalize-path"), 1);
47
- function normalizePath(path7) {
48
- return (0, import_normalize_path.default)(path7);
47
+ function normalizePath(path6) {
48
+ return (0, import_normalize_path.default)(path6);
49
49
  }
50
50
  var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
51
51
  var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
@@ -56,14 +56,22 @@ function getEntrypointName(entrypointsDir, inputPath) {
56
56
  const name = relativePath.split(/[\.\/\\]/, 2)[0];
57
57
  return name;
58
58
  }
59
+ function getEntrypointOutputFile(entrypoint, ext) {
60
+ return (0, import_node_path2.resolve)(entrypoint.outputDir, `${entrypoint.name}${ext}`);
61
+ }
62
+ function getEntrypointBundlePath(entrypoint, outDir, ext) {
63
+ return normalizePath(
64
+ (0, import_node_path2.relative)(outDir, getEntrypointOutputFile(entrypoint, ext))
65
+ );
66
+ }
59
67
 
60
- // src/core/vite-plugins/devHtmlPrerender.ts
68
+ // src/core/builders/vite/plugins/devHtmlPrerender.ts
61
69
  var import_linkedom = require("linkedom");
62
- var import_path = require("path");
70
+ var import_node_path3 = require("path");
63
71
  var reactRefreshPreamble = "";
64
72
  function devHtmlPrerender(config) {
65
73
  const htmlReloadId = "@wxt/reload-html";
66
- const resolvedHtmlReloadId = (0, import_path.resolve)(
74
+ const resolvedHtmlReloadId = (0, import_node_path3.resolve)(
67
75
  config.root,
68
76
  "node_modules/wxt/dist/virtual/reload-html.js"
69
77
  );
@@ -94,11 +102,11 @@ function devHtmlPrerender(config) {
94
102
  const src = element.getAttribute(attr);
95
103
  if (!src)
96
104
  return;
97
- if ((0, import_path.isAbsolute)(src)) {
105
+ if ((0, import_node_path3.isAbsolute)(src)) {
98
106
  element.setAttribute(attr, server.origin + src);
99
107
  } else if (src.startsWith(".")) {
100
- const abs = (0, import_path.resolve)((0, import_path.dirname)(id), src);
101
- const pathname = (0, import_path.relative)(config.root, abs);
108
+ const abs = (0, import_node_path3.resolve)((0, import_node_path3.dirname)(id), src);
109
+ const pathname = (0, import_node_path3.relative)(config.root, abs);
102
110
  element.setAttribute(attr, `${server.origin}/${pathname}`);
103
111
  }
104
112
  });
@@ -123,11 +131,7 @@ function devHtmlPrerender(config) {
123
131
  const originalUrl = `${server.origin}${ctx.path}`;
124
132
  const name = getEntrypointName(config.entrypointsDir, ctx.filename);
125
133
  const url = `${server.origin}/${name}.html`;
126
- const serverHtml = await server.transformIndexHtml(
127
- url,
128
- html,
129
- originalUrl
130
- );
134
+ const serverHtml = await server.transformHtml(url, html, originalUrl);
131
135
  const { document } = (0, import_linkedom.parseHTML)(serverHtml);
132
136
  const reactRefreshScript = Array.from(
133
137
  document.querySelectorAll("script[type=module]")
@@ -175,20 +179,18 @@ function devHtmlPrerender(config) {
175
179
  ];
176
180
  }
177
181
 
178
- // src/core/vite-plugins/devServerGlobals.ts
179
- function devServerGlobals(internalConfig) {
182
+ // src/core/builders/vite/plugins/devServerGlobals.ts
183
+ function devServerGlobals(config) {
180
184
  return {
181
185
  name: "wxt:dev-server-globals",
182
186
  config() {
183
- if (internalConfig.server == null || internalConfig.command == "build")
187
+ if (config.server == null || config.command == "build")
184
188
  return;
185
189
  return {
186
190
  define: {
187
191
  __DEV_SERVER_PROTOCOL__: JSON.stringify("ws:"),
188
- __DEV_SERVER_HOSTNAME__: JSON.stringify(
189
- internalConfig.server.hostname
190
- ),
191
- __DEV_SERVER_PORT__: JSON.stringify(internalConfig.server.port)
192
+ __DEV_SERVER_HOSTNAME__: JSON.stringify(config.server.hostname),
193
+ __DEV_SERVER_PORT__: JSON.stringify(config.server.port)
192
194
  }
193
195
  };
194
196
  }
@@ -247,7 +249,7 @@ async function fetchCached(url, config) {
247
249
  return content;
248
250
  }
249
251
 
250
- // src/core/vite-plugins/download.ts
252
+ // src/core/builders/vite/plugins/download.ts
251
253
  function download(config) {
252
254
  return {
253
255
  name: "wxt:download",
@@ -264,15 +266,70 @@ function download(config) {
264
266
  };
265
267
  }
266
268
 
267
- // src/core/vite-plugins/multipageMove.ts
268
- var import_node_path3 = require("path");
269
+ // src/core/builders/vite/plugins/multipageMove.ts
270
+ var import_node_path4 = require("path");
269
271
  var import_fs_extra = __toESM(require("fs-extra"), 1);
272
+ function multipageMove(entrypoints, config) {
273
+ return {
274
+ name: "wxt:multipage-move",
275
+ async writeBundle(_, bundle) {
276
+ for (const oldBundlePath in bundle) {
277
+ const entrypoint = entrypoints.find(
278
+ (entry) => !!normalizePath(entry.inputPath).endsWith(oldBundlePath)
279
+ );
280
+ if (entrypoint == null) {
281
+ config.logger.debug(
282
+ `No entrypoint found for ${oldBundlePath}, leaving in chunks directory`
283
+ );
284
+ continue;
285
+ }
286
+ const newBundlePath = getEntrypointBundlePath(
287
+ entrypoint,
288
+ config.outDir,
289
+ (0, import_node_path4.extname)(oldBundlePath)
290
+ );
291
+ if (newBundlePath === oldBundlePath) {
292
+ config.logger.debug(
293
+ "HTML file is already in the correct location",
294
+ oldBundlePath
295
+ );
296
+ continue;
297
+ }
298
+ const oldAbsPath = (0, import_node_path4.resolve)(config.outDir, oldBundlePath);
299
+ const newAbsPath = (0, import_node_path4.resolve)(config.outDir, newBundlePath);
300
+ await (0, import_fs_extra.ensureDir)((0, import_node_path4.dirname)(newAbsPath));
301
+ await import_fs_extra.default.move(oldAbsPath, newAbsPath, { overwrite: true });
302
+ const renamedChunk = {
303
+ ...bundle[oldBundlePath],
304
+ fileName: newBundlePath
305
+ };
306
+ delete bundle[oldBundlePath];
307
+ bundle[newBundlePath] = renamedChunk;
308
+ }
309
+ removeEmptyDirs(config.outDir);
310
+ }
311
+ };
312
+ }
313
+ async function removeEmptyDirs(dir) {
314
+ const files = await import_fs_extra.default.readdir(dir);
315
+ for (const file of files) {
316
+ const filePath = (0, import_node_path4.join)(dir, file);
317
+ const stats = await import_fs_extra.default.stat(filePath);
318
+ if (stats.isDirectory()) {
319
+ await removeEmptyDirs(filePath);
320
+ }
321
+ }
322
+ try {
323
+ await import_fs_extra.default.rmdir(dir);
324
+ } catch {
325
+ }
326
+ }
270
327
 
271
- // src/core/vite-plugins/unimport.ts
328
+ // src/core/builders/vite/plugins/unimport.ts
272
329
  var import_unimport = require("unimport");
273
330
 
274
331
  // src/core/utils/unimport.ts
275
- var import_vite = require("vite");
332
+ var import_defu = require("defu");
276
333
  function getUnimportOptions(config) {
277
334
  if (config.imports === false)
278
335
  return false;
@@ -291,14 +348,11 @@ function getUnimportOptions(config) {
291
348
  warn: config.logger.warn,
292
349
  dirs: ["components", "composables", "hooks", "utils"]
293
350
  };
294
- return (0, import_vite.mergeConfig)(
295
- defaultOptions,
296
- config.imports
297
- );
351
+ return (0, import_defu.defu)(config.imports, defaultOptions);
298
352
  }
299
353
 
300
- // src/core/vite-plugins/unimport.ts
301
- var import_path2 = require("path");
354
+ // src/core/builders/vite/plugins/unimport.ts
355
+ var import_path = require("path");
302
356
  var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
303
357
  ".js",
304
358
  ".jsx",
@@ -320,16 +374,16 @@ function unimport(config) {
320
374
  async transform(code, id) {
321
375
  if (id.includes("node_modules"))
322
376
  return;
323
- if (!ENABLED_EXTENSIONS.has((0, import_path2.extname)(id)))
377
+ if (!ENABLED_EXTENSIONS.has((0, import_path.extname)(id)))
324
378
  return;
325
379
  return unimport2.injectImports(code, id);
326
380
  }
327
381
  };
328
382
  }
329
383
 
330
- // src/core/vite-plugins/virtualEntrypoint.ts
384
+ // src/core/builders/vite/plugins/virtualEntrypoint.ts
331
385
  var import_fs_extra2 = __toESM(require("fs-extra"), 1);
332
- var import_path3 = require("path");
386
+ var import_path2 = require("path");
333
387
  function virtualEntrypoint(type, config) {
334
388
  const virtualId = `virtual:wxt-${type}?`;
335
389
  const resolvedVirtualId = `\0${virtualId}`;
@@ -347,7 +401,7 @@ function virtualEntrypoint(type, config) {
347
401
  return;
348
402
  const inputPath = id.replace(resolvedVirtualId, "");
349
403
  const template = await import_fs_extra2.default.readFile(
350
- (0, import_path3.resolve)(
404
+ (0, import_path2.resolve)(
351
405
  config.root,
352
406
  `node_modules/wxt/dist/virtual/${type}-entrypoint.js`
353
407
  ),
@@ -358,7 +412,7 @@ function virtualEntrypoint(type, config) {
358
412
  };
359
413
  }
360
414
 
361
- // src/core/vite-plugins/tsconfigPaths.ts
415
+ // src/core/builders/vite/plugins/tsconfigPaths.ts
362
416
  function tsconfigPaths(config) {
363
417
  return {
364
418
  name: "wxt:aliases",
@@ -372,7 +426,10 @@ function tsconfigPaths(config) {
372
426
  };
373
427
  }
374
428
 
375
- // src/core/vite-plugins/noopBackground.ts
429
+ // src/core/utils/constants.ts
430
+ var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
431
+
432
+ // src/core/builders/vite/plugins/noopBackground.ts
376
433
  function noopBackground() {
377
434
  const virtualModuleId = VIRTUAL_NOOP_BACKGROUND_MODULE_ID;
378
435
  const resolvedVirtualModuleId = "\0" + virtualModuleId;
@@ -390,9 +447,32 @@ export default defineBackground(() => void 0)`;
390
447
  }
391
448
  };
392
449
  }
393
- var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
394
450
 
395
- // src/core/vite-plugins/bundleAnalysis.ts
451
+ // src/core/builders/vite/plugins/cssEntrypoints.ts
452
+ function cssEntrypoints(entrypoint, config) {
453
+ return {
454
+ name: "wxt:css-entrypoint",
455
+ config() {
456
+ return {
457
+ build: {
458
+ rollupOptions: {
459
+ output: {
460
+ assetFileNames: () => getEntrypointBundlePath(entrypoint, config.outDir, ".css")
461
+ }
462
+ }
463
+ }
464
+ };
465
+ },
466
+ generateBundle(_, bundle) {
467
+ Object.keys(bundle).forEach((file) => {
468
+ if (file.endsWith(".js"))
469
+ delete bundle[file];
470
+ });
471
+ }
472
+ };
473
+ }
474
+
475
+ // src/core/builders/vite/plugins/bundleAnalysis.ts
396
476
  var import_rollup_plugin_visualizer = require("rollup-plugin-visualizer");
397
477
  var increment = 0;
398
478
  function bundleAnalysis() {
@@ -448,11 +528,20 @@ function getGlobals(config) {
448
528
  }
449
529
  ];
450
530
  }
531
+ function getEntrypointGlobals(entrypointName) {
532
+ return [
533
+ {
534
+ name: surroundInUnderscore("ENTRYPOINT"),
535
+ value: entrypointName,
536
+ type: `string`
537
+ }
538
+ ];
539
+ }
451
540
  function surroundInUnderscore(name) {
452
541
  return `__${name}__`;
453
542
  }
454
543
 
455
- // src/core/vite-plugins/globals.ts
544
+ // src/core/builders/vite/plugins/globals.ts
456
545
  function globals(config) {
457
546
  return {
458
547
  name: "wxt:globals",
@@ -468,8 +557,8 @@ function globals(config) {
468
557
  };
469
558
  }
470
559
 
471
- // src/core/vite-plugins/webextensionPolyfillAlias.ts
472
- var import_node_path4 = __toESM(require("path"), 1);
560
+ // src/core/builders/vite/plugins/webextensionPolyfillAlias.ts
561
+ var import_node_path5 = __toESM(require("path"), 1);
473
562
  function webextensionPolyfillAlias(config) {
474
563
  return {
475
564
  name: "wxt:webextension-polyfill-test-alias",
@@ -477,7 +566,7 @@ function webextensionPolyfillAlias(config) {
477
566
  return {
478
567
  resolve: {
479
568
  alias: {
480
- "webextension-polyfill": import_node_path4.default.resolve(
569
+ "webextension-polyfill": import_node_path5.default.resolve(
481
570
  config.root,
482
571
  "node_modules/wxt/dist/virtual/mock-browser"
483
572
  )
@@ -488,7 +577,7 @@ function webextensionPolyfillAlias(config) {
488
577
  };
489
578
  }
490
579
 
491
- // src/core/vite-plugins/webextensionPolyfillInlineDeps.ts
580
+ // src/core/builders/vite/plugins/webextensionPolyfillInlineDeps.ts
492
581
  function webextensionPolyfillInlineDeps() {
493
582
  return {
494
583
  name: "wxt:testing-inline-deps",
@@ -507,7 +596,7 @@ function webextensionPolyfillInlineDeps() {
507
596
  };
508
597
  }
509
598
 
510
- // src/core/vite-plugins/excludeBrowserPolyfill.ts
599
+ // src/core/builders/vite/plugins/excludeBrowserPolyfill.ts
511
600
  function excludeBrowserPolyfill(config) {
512
601
  const virtualId = "virtual:wxt-webextension-polyfill-disabled";
513
602
  return {
@@ -531,13 +620,26 @@ function excludeBrowserPolyfill(config) {
531
620
  };
532
621
  }
533
622
 
534
- // src/core/utils/building/build-entrypoints.ts
535
- var vite = __toESM(require("vite"), 1);
623
+ // src/core/builders/vite/plugins/entrypointGroupGlobals.ts
624
+ function entrypointGroupGlobals(entrypointGroup) {
625
+ return {
626
+ name: "wxt:entrypoint-group-globals",
627
+ config() {
628
+ const define = {};
629
+ let name = Array.isArray(entrypointGroup) ? "html" : entrypointGroup.name;
630
+ for (const global of getEntrypointGlobals(name)) {
631
+ define[global.name] = JSON.stringify(global.value);
632
+ }
633
+ return {
634
+ define
635
+ };
636
+ }
637
+ };
638
+ }
536
639
 
537
640
  // src/core/utils/fs.ts
538
641
  var import_fs_extra3 = __toESM(require("fs-extra"), 1);
539
642
  var import_fast_glob = __toESM(require("fast-glob"), 1);
540
- var import_node_path5 = __toESM(require("path"), 1);
541
643
  async function writeFileIfDifferent(file, newContents) {
542
644
  const existingContents = await import_fs_extra3.default.readFile(file, "utf-8").catch(() => void 0);
543
645
  if (existingContents !== newContents) {
@@ -605,23 +707,22 @@ var import_node_path6 = __toESM(require("path"), 1);
605
707
  // src/core/utils/building/get-internal-config.ts
606
708
  var import_c12 = require("c12");
607
709
  var import_node_path7 = __toESM(require("path"), 1);
608
- var vite2 = __toESM(require("vite"), 1);
609
710
 
610
711
  // src/core/utils/cache.ts
611
712
  var import_fs_extra7 = __toESM(require("fs-extra"), 1);
612
- var import_path4 = require("path");
713
+ var import_path3 = require("path");
613
714
  function createFsCache(wxtDir) {
614
- const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
715
+ const getPath = (key) => (0, import_path3.resolve)(wxtDir, "cache", encodeURIComponent(key));
615
716
  return {
616
717
  async set(key, value) {
617
- const path7 = getPath(key);
618
- await (0, import_fs_extra7.ensureDir)((0, import_path4.dirname)(path7));
619
- await writeFileIfDifferent(path7, value);
718
+ const path6 = getPath(key);
719
+ await (0, import_fs_extra7.ensureDir)((0, import_path3.dirname)(path6));
720
+ await writeFileIfDifferent(path6, value);
620
721
  },
621
722
  async get(key) {
622
- const path7 = getPath(key);
723
+ const path6 = getPath(key);
623
724
  try {
624
- return await import_fs_extra7.default.readFile(path7, "utf-8");
725
+ return await import_fs_extra7.default.readFile(path6, "utf-8");
625
726
  } catch {
626
727
  return void 0;
627
728
  }
@@ -631,8 +732,204 @@ function createFsCache(wxtDir) {
631
732
 
632
733
  // src/core/utils/building/get-internal-config.ts
633
734
  var import_consola = __toESM(require("consola"), 1);
634
- var import_defu = __toESM(require("defu"), 1);
635
- async function getInternalConfig(inlineConfig, command) {
735
+
736
+ // src/core/builders/vite/index.ts
737
+ async function craeteViteBuilder(inlineConfig, userConfig, wxtConfig) {
738
+ const vite = await import("vite");
739
+ const getBaseConfig = async () => {
740
+ const resolvedInlineConfig = await inlineConfig.vite?.(wxtConfig.env) ?? {};
741
+ const resolvedUserConfig = await userConfig.vite?.(wxtConfig.env) ?? {};
742
+ const config = vite.mergeConfig(
743
+ resolvedUserConfig,
744
+ resolvedInlineConfig
745
+ );
746
+ config.root = wxtConfig.root;
747
+ config.configFile = false;
748
+ config.logLevel = "warn";
749
+ config.mode = wxtConfig.mode;
750
+ config.build ??= {};
751
+ config.build.outDir = wxtConfig.outDir;
752
+ config.build.emptyOutDir = false;
753
+ config.plugins ??= [];
754
+ config.plugins.push(
755
+ download(wxtConfig),
756
+ devHtmlPrerender(wxtConfig),
757
+ unimport(wxtConfig),
758
+ virtualEntrypoint("background", wxtConfig),
759
+ virtualEntrypoint("content-script", wxtConfig),
760
+ virtualEntrypoint("unlisted-script", wxtConfig),
761
+ devServerGlobals(wxtConfig),
762
+ tsconfigPaths(wxtConfig),
763
+ noopBackground(),
764
+ globals(wxtConfig),
765
+ excludeBrowserPolyfill(wxtConfig)
766
+ );
767
+ if (wxtConfig.analysis.enabled) {
768
+ config.plugins.push(bundleAnalysis());
769
+ }
770
+ return config;
771
+ };
772
+ const getLibModeConfig = (entrypoint) => {
773
+ const isVirtual = [
774
+ "background",
775
+ "content-script",
776
+ "unlisted-script"
777
+ ].includes(entrypoint.type);
778
+ const entry = isVirtual ? `virtual:wxt-${entrypoint.type}?${entrypoint.inputPath}` : entrypoint.inputPath;
779
+ const plugins = [
780
+ entrypointGroupGlobals(entrypoint)
781
+ ];
782
+ if (entrypoint.type === "content-script-style" || entrypoint.type === "unlisted-style") {
783
+ plugins.push(cssEntrypoints(entrypoint, wxtConfig));
784
+ }
785
+ const libMode = {
786
+ mode: wxtConfig.mode,
787
+ plugins,
788
+ build: {
789
+ lib: {
790
+ entry,
791
+ formats: ["iife"],
792
+ name: "_",
793
+ fileName: entrypoint.name
794
+ },
795
+ rollupOptions: {
796
+ output: {
797
+ // There's only a single output for this build, so we use the desired bundle path for the
798
+ // entry output (like "content-scripts/overlay.js")
799
+ entryFileNames: getEntrypointBundlePath(
800
+ entrypoint,
801
+ wxtConfig.outDir,
802
+ ".js"
803
+ ),
804
+ // Output content script CSS to `content-scripts/`, but all other scripts are written to
805
+ // `assets/`.
806
+ assetFileNames: ({ name }) => {
807
+ if (entrypoint.type === "content-script" && name?.endsWith("css")) {
808
+ return `content-scripts/${entrypoint.name}.[ext]`;
809
+ } else {
810
+ return `assets/${entrypoint.name}.[ext]`;
811
+ }
812
+ }
813
+ }
814
+ }
815
+ },
816
+ define: {
817
+ // See https://github.com/aklinker1/vite-plugin-web-extension/issues/96
818
+ "process.env.NODE_ENV": JSON.stringify(wxtConfig.mode)
819
+ }
820
+ };
821
+ return libMode;
822
+ };
823
+ const getMultiPageConfig = (entrypoints) => {
824
+ return {
825
+ mode: wxtConfig.mode,
826
+ plugins: [
827
+ multipageMove(entrypoints, wxtConfig),
828
+ entrypointGroupGlobals(entrypoints)
829
+ ],
830
+ build: {
831
+ rollupOptions: {
832
+ input: entrypoints.reduce((input, entry) => {
833
+ input[entry.name] = entry.inputPath;
834
+ return input;
835
+ }, {}),
836
+ output: {
837
+ // Include a hash to prevent conflicts
838
+ chunkFileNames: "chunks/[name]-[hash].js",
839
+ // Include a hash to prevent conflicts
840
+ entryFileNames: "chunks/[name]-[hash].js",
841
+ // We can't control the "name", so we need a hash to prevent conflicts
842
+ assetFileNames: "assets/[name]-[hash].[ext]"
843
+ }
844
+ }
845
+ }
846
+ };
847
+ };
848
+ const getCssConfig = (entrypoint) => {
849
+ return {
850
+ mode: wxtConfig.mode,
851
+ plugins: [entrypointGroupGlobals(entrypoint)],
852
+ build: {
853
+ rollupOptions: {
854
+ input: {
855
+ [entrypoint.name]: entrypoint.inputPath
856
+ },
857
+ output: {
858
+ assetFileNames: () => {
859
+ if (entrypoint.type === "content-script-style") {
860
+ return `content-scripts/${entrypoint.name}.[ext]`;
861
+ } else {
862
+ return `assets/${entrypoint.name}.[ext]`;
863
+ }
864
+ }
865
+ }
866
+ }
867
+ }
868
+ };
869
+ };
870
+ return {
871
+ name: "Vite",
872
+ version: vite.version,
873
+ async build(group) {
874
+ let entryConfig;
875
+ if (Array.isArray(group))
876
+ entryConfig = getMultiPageConfig(group);
877
+ else if (group.inputPath.endsWith(".css"))
878
+ entryConfig = getCssConfig(group);
879
+ else
880
+ entryConfig = getLibModeConfig(group);
881
+ const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
882
+ const result = await vite.build(buildConfig);
883
+ return {
884
+ entrypoints: group,
885
+ chunks: getBuildOutputChunks(result)
886
+ };
887
+ },
888
+ async createServer(info) {
889
+ const serverConfig = {
890
+ server: {
891
+ port: info.port,
892
+ strictPort: true,
893
+ host: info.hostname,
894
+ origin: info.origin
895
+ }
896
+ };
897
+ const baseConfig = await getBaseConfig();
898
+ const viteServer = await vite.createServer(
899
+ vite.mergeConfig(baseConfig, serverConfig)
900
+ );
901
+ const server = {
902
+ async listen() {
903
+ await viteServer.listen(info.port);
904
+ },
905
+ transformHtml(...args) {
906
+ return viteServer.transformIndexHtml(...args);
907
+ },
908
+ ws: {
909
+ send(message, payload) {
910
+ return viteServer.ws.send(message, payload);
911
+ },
912
+ on(message, cb) {
913
+ viteServer.ws.on(message, cb);
914
+ }
915
+ },
916
+ watcher: viteServer.watcher
917
+ };
918
+ return server;
919
+ }
920
+ };
921
+ }
922
+ function getBuildOutputChunks(result) {
923
+ if ("on" in result)
924
+ throw Error("wxt does not support vite watch mode.");
925
+ if (Array.isArray(result))
926
+ return result.flatMap(({ output }) => output);
927
+ return result.output;
928
+ }
929
+
930
+ // src/core/utils/building/get-internal-config.ts
931
+ var import_defu2 = __toESM(require("defu"), 1);
932
+ async function getInternalConfig(inlineConfig, command, server) {
636
933
  let userConfig = {};
637
934
  let userConfigMetadata;
638
935
  if (inlineConfig.configFile !== false) {
@@ -702,8 +999,6 @@ async function getInternalConfig(inlineConfig, command) {
702
999
  runnerConfig,
703
1000
  srcDir,
704
1001
  typesDir,
705
- vite: () => ({}),
706
- // Real value added after this object is initialized.
707
1002
  wxtDir,
708
1003
  zip: resolveInternalZipConfig(root, mergedConfig),
709
1004
  transformManifest(manifest) {
@@ -718,10 +1013,18 @@ async function getInternalConfig(inlineConfig, command) {
718
1013
  alias,
719
1014
  experimental: {
720
1015
  includeBrowserPolyfill: mergedConfig.experimental?.includeBrowserPolyfill ?? true
721
- }
1016
+ },
1017
+ server
1018
+ };
1019
+ const builder = await craeteViteBuilder(
1020
+ inlineConfig,
1021
+ userConfig,
1022
+ finalConfig
1023
+ );
1024
+ return {
1025
+ ...finalConfig,
1026
+ builder
722
1027
  };
723
- finalConfig.vite = (env2) => resolveInternalViteConfig(env2, mergedConfig, finalConfig);
724
- return finalConfig;
725
1028
  }
726
1029
  async function resolveManifestConfig(env, manifest) {
727
1030
  return await (typeof manifest === "function" ? manifest(env) : manifest ?? {});
@@ -733,26 +1036,18 @@ function mergeInlineConfig(inlineConfig, userConfig) {
733
1036
  } else if (userConfig.imports == null && inlineConfig.imports == null) {
734
1037
  imports = void 0;
735
1038
  } else {
736
- imports = vite2.mergeConfig(
737
- userConfig.imports ?? {},
738
- inlineConfig.imports ?? {}
739
- );
1039
+ imports = (0, import_defu2.default)(inlineConfig.imports ?? {}, userConfig.imports ?? {});
740
1040
  }
741
1041
  const manifest = async (env) => {
742
1042
  const user = await resolveManifestConfig(env, userConfig.manifest);
743
1043
  const inline = await resolveManifestConfig(env, inlineConfig.manifest);
744
- return vite2.mergeConfig(user, inline);
1044
+ return (0, import_defu2.default)(inline, user);
745
1045
  };
746
- const viteConfig = async (env) => {
747
- const user = await userConfig.vite?.(env);
748
- const inline = await inlineConfig.vite?.(env);
749
- return vite2.mergeConfig(user ?? {}, inline ?? {});
750
- };
751
- const runner = (0, import_defu.default)(
1046
+ const runner = (0, import_defu2.default)(
752
1047
  inlineConfig.runner ?? {},
753
1048
  userConfig.runner ?? {}
754
1049
  );
755
- const zip = (0, import_defu.default)(
1050
+ const zip = (0, import_defu2.default)(
756
1051
  inlineConfig.zip ?? {},
757
1052
  userConfig.zip ?? {}
758
1053
  );
@@ -771,7 +1066,6 @@ function mergeInlineConfig(inlineConfig, userConfig) {
771
1066
  runner,
772
1067
  srcDir: inlineConfig.srcDir ?? userConfig.srcDir,
773
1068
  outDir: inlineConfig.outDir ?? userConfig.outDir,
774
- vite: viteConfig,
775
1069
  zip,
776
1070
  analysis: {
777
1071
  enabled: inlineConfig.analysis?.enabled ?? userConfig.analysis?.enabled,
@@ -785,6 +1079,7 @@ function mergeInlineConfig(inlineConfig, userConfig) {
785
1079
  ...userConfig.experimental,
786
1080
  ...inlineConfig.experimental
787
1081
  },
1082
+ vite: void 0,
788
1083
  transformManifest: void 0
789
1084
  };
790
1085
  }
@@ -809,38 +1104,6 @@ function resolveInternalZipConfig(root, mergedConfig) {
809
1104
  ]
810
1105
  };
811
1106
  }
812
- async function resolveInternalViteConfig(env, mergedConfig, finalConfig) {
813
- const internalVite = await mergedConfig.vite?.(env) ?? {};
814
- internalVite.root = finalConfig.root;
815
- internalVite.configFile = false;
816
- internalVite.logLevel = "warn";
817
- internalVite.mode = env.mode;
818
- internalVite.build ??= {};
819
- internalVite.build.outDir = finalConfig.outDir;
820
- internalVite.build.emptyOutDir = false;
821
- internalVite.plugins ??= [];
822
- internalVite.plugins.push(download(finalConfig));
823
- internalVite.plugins.push(devHtmlPrerender(finalConfig));
824
- internalVite.plugins.push(unimport(finalConfig));
825
- internalVite.plugins.push(
826
- virtualEntrypoint("background", finalConfig)
827
- );
828
- internalVite.plugins.push(
829
- virtualEntrypoint("content-script", finalConfig)
830
- );
831
- internalVite.plugins.push(
832
- virtualEntrypoint("unlisted-script", finalConfig)
833
- );
834
- internalVite.plugins.push(devServerGlobals(finalConfig));
835
- internalVite.plugins.push(tsconfigPaths(finalConfig));
836
- internalVite.plugins.push(noopBackground());
837
- if (finalConfig.analysis.enabled) {
838
- internalVite.plugins.push(bundleAnalysis());
839
- }
840
- internalVite.plugins.push(globals(finalConfig));
841
- internalVite.plugins.push(excludeBrowserPolyfill(finalConfig));
842
- return internalVite;
843
- }
844
1107
 
845
1108
  // src/core/utils/building/import-entrypoint.ts
846
1109
  var import_jiti = __toESM(require("jiti"), 1);
@@ -850,7 +1113,6 @@ var import_esbuild = require("esbuild");
850
1113
 
851
1114
  // src/core/utils/building/internal-build.ts
852
1115
  var import_picocolors4 = __toESM(require("picocolors"), 1);
853
- var vite3 = __toESM(require("vite"), 1);
854
1116
  var import_fs_extra12 = __toESM(require("fs-extra"), 1);
855
1117
 
856
1118
  // src/core/utils/log/printFileList.ts
@@ -887,7 +1149,7 @@ var import_fs_extra10 = __toESM(require("fs-extra"), 1);
887
1149
 
888
1150
  // src/core/utils/manifest.ts
889
1151
  var import_immer = require("immer");
890
- var import_defu2 = __toESM(require("defu"), 1);
1152
+ var import_defu3 = __toESM(require("defu"), 1);
891
1153
 
892
1154
  // src/testing/wxt-vitest-plugin.ts
893
1155
  function WxtVitest(inlineConfig) {