Skip to content

Commit 0e5263b

Browse files
committed
refactor: use static imports now that wxt is esm-only
Since #848, there's no need to do all this async work. At least, as far as I could tell...
1 parent 67dab8e commit 0e5263b

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

packages/wxt/src/core/builders/vite/plugins/devServerGlobals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Plugin } from 'vite';
2-
import { ResolvedConfig, WxtDevServer } from '../../../../types';
1+
import type { Plugin } from 'vite';
2+
import type { ResolvedConfig, WxtDevServer } from '../../../../types';
33

44
/**
55
* Defines global constants about the dev server. Helps scripts connect to the server's web socket.

packages/wxt/src/core/builders/vite/plugins/download.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Plugin } from 'vite';
2-
import { ResolvedConfig } from '../../../../types';
1+
import type { Plugin } from 'vite';
2+
import type { ResolvedConfig } from '../../../../types';
33
import { fetchCached } from '../../../utils/network';
44

55
/**

packages/wxt/src/core/builders/vite/plugins/noopBackground.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'vite';
1+
import type { Plugin } from 'vite';
22
import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from '../../../utils/constants';
33

44
/**

packages/wxt/src/core/builders/vite/plugins/resolveVirtualModules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin } from 'vite';
1+
import type { Plugin } from 'vite';
22
import { ResolvedConfig } from '../../../../types';
33
import { normalizePath } from '../../../utils/paths';
44
import {

packages/wxt/src/core/resolve-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ export async function mergeBuilderConfig(
577577
if (vite) {
578578
return {
579579
vite: async (env) => {
580-
const resolvedInlineConfig = (await inlineConfig.vite?.(env)) ?? {};
581-
const resolvedUserConfig = (await userConfig.vite?.(env)) ?? {};
580+
const [resolvedInlineConfig = {}, resolvedUserConfig = {}] =
581+
await Promise.all([inlineConfig.vite?.(env), userConfig.vite?.(env)]);
582582
return vite.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
583583
},
584584
};

packages/wxt/src/core/wxt.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export async function registerWxt(
2626

2727
const hooks = createHooks<WxtHooks>();
2828
const config = await resolveConfig(inlineConfig, command);
29-
const builder = await createViteBuilder(config, hooks, () => wxt.server);
30-
const pm = await createWxtPackageManager(config.root);
29+
const [builder, pm] = await Promise.all([
30+
createViteBuilder(config, hooks, () => wxt.server),
31+
createWxtPackageManager(config.root),
32+
]);
3133

3234
wxt = {
3335
config,

packages/wxt/src/modules.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
WxtModuleOptions,
1111
WxtModuleSetup,
1212
} from './types';
13-
import * as vite from 'vite';
13+
import type * as vite from 'vite';
1414
import glob from 'fast-glob';
1515
import { resolve } from 'node:path';
1616
import type { UnimportOptions } from 'unimport';
@@ -109,7 +109,10 @@ export function addViteConfig(
109109
wxt.hooks.hook('config:resolved', (wxt) => {
110110
const userVite = wxt.config.vite;
111111
wxt.config.vite = async (env) => {
112-
const fromUser = await userVite(env);
112+
const [vite, fromUser] = await Promise.all([
113+
import('vite'),
114+
userVite(env),
115+
]);
113116
const fromModule = viteConfig(env) ?? {};
114117
return vite.mergeConfig(fromModule, fromUser);
115118
};

0 commit comments

Comments
 (0)