diff --git a/.changeset/tame-comics-repair.md b/.changeset/tame-comics-repair.md new file mode 100644 index 0000000..f68a899 --- /dev/null +++ b/.changeset/tame-comics-repair.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-solid': patch +--- + +Support Vite 6's `resolve.conditions` breaking change diff --git a/src/index.ts b/src/index.ts index 006b54b..8747ecc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { readFileSync } from 'fs'; import { mergeAndConcat } from 'merge-anything'; import { createRequire } from 'module'; import solidRefresh from 'solid-refresh/babel'; -import { createFilter } from 'vite'; +import { createFilter, version } from 'vite'; import type { Alias, AliasOptions, Plugin, FilterPattern } from 'vite'; import { crawlFrameworkPkgs } from 'vitefu'; @@ -14,6 +14,8 @@ const runtimePublicPath = '/@solid-refresh'; const runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs'); const runtimeCode = readFileSync(runtimeFilePath, 'utf-8'); +const isVite6 = version.startsWith('6.'); + /** Possible options for the extensions property */ export interface ExtensionOptions { typescript?: boolean; @@ -236,11 +238,13 @@ export default function solidPlugin(options: Partial = {}): Plugin { */ // esbuild: { include: /\.ts$/ }, resolve: { - conditions: [ - 'solid', - ...(replaceDev ? ['development'] : []), - ...(userConfig.mode === 'test' && !options.ssr ? ['browser'] : []), - ], + conditions: isVite6 + ? undefined + : [ + 'solid', + ...(replaceDev ? ['development'] : []), + ...(userConfig.mode === 'test' && !options.ssr ? ['browser'] : []), + ], dedupe: nestedDeps, alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }], }, @@ -253,6 +257,22 @@ export default function solidPlugin(options: Partial = {}): Plugin { }; }, + // @ts-ignore This hook only works in Vite 6 + async configEnvironment(_, config, opts) { + config.resolve ??= {}; + // Emulate Vite default fallback for `resolve.conditions` if not set + if (config.resolve.conditions == null) { + // @ts-ignore These exports only exist in Vite 6 + const { defaultClientConditions, defaultServerConditions } = await import('vite'); + if (config.consumer === 'client' || opts.isSsrTargetWebworker) { + config.resolve.conditions = [...defaultClientConditions]; + } else { + config.resolve.conditions = [...defaultServerConditions]; + } + } + config.resolve.conditions.push('solid'); + }, + configResolved(config) { needHmr = config.command === 'serve' && config.mode !== 'production' && options.hot !== false; },