Skip to content

Commit b19050a

Browse files
Copilotbirkskyum
andauthored
Fix SSR resolve.external being unconditionally applied in Vite 6+ (#236)
* Initial plan * Initial plan Co-authored-by: birkskyum <[email protected]> * Fix SSR resolve.external being unconditionally applied - Move SSR config from config hook to configEnvironment hook for Vite 6+ - Only set resolve.external if noExternal !== true to avoid conflicts - Maintain backward compatibility with Vite 3, 4, 5 Co-authored-by: birkskyum <[email protected]> * delete lockfile * add changeset --------- Co-authored-by: birkskyum <[email protected]> Co-authored-by: Birk Skyum <[email protected]>
1 parent d5b8260 commit b19050a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.changeset/fiery-suns-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vite-plugin-solid': patch
3+
---
4+
5+
Fix SSR resolve.external being unconditionally applied in Vite 6+

src/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
198198
let replaceDev = false;
199199
let projectRoot = process.cwd();
200200
let isTestMode = false;
201+
let solidPkgsConfig: Awaited<ReturnType<typeof crawlFrameworkPkgs>>;
201202

202203
return {
203204
name: 'solid',
@@ -212,7 +213,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
212213
if (!userConfig.resolve) userConfig.resolve = {};
213214
userConfig.resolve.alias = normalizeAliases(userConfig.resolve && userConfig.resolve.alias);
214215

215-
const solidPkgsConfig = await crawlFrameworkPkgs({
216+
solidPkgsConfig = await crawlFrameworkPkgs({
216217
viteUserConfig: userConfig,
217218
root: projectRoot || process.cwd(),
218219
isBuild: command === 'build',
@@ -277,7 +278,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
277278
include: [...nestedDeps, ...solidPkgsConfig.optimizeDeps.include],
278279
exclude: solidPkgsConfig.optimizeDeps.exclude,
279280
},
280-
ssr: solidPkgsConfig.ssr,
281+
...(!isVite6 ? { ssr: solidPkgsConfig.ssr } : {}),
281282
...(test.server ? { test } : {}),
282283
};
283284
},
@@ -301,6 +302,21 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
301302
...(isTestMode && !opts.isSsrTargetWebworker && !options.ssr ? ['browser'] : []),
302303
...config.resolve.conditions,
303304
];
305+
306+
// Set resolve.noExternal and resolve.external for SSR environment (Vite 6+)
307+
// Only set resolve.external if noExternal is not true (to avoid conflicts with plugins like Cloudflare)
308+
if (isVite6 && name === 'ssr' && solidPkgsConfig) {
309+
if (config.resolve.noExternal !== true) {
310+
config.resolve.noExternal = [
311+
...(Array.isArray(config.resolve.noExternal) ? config.resolve.noExternal : []),
312+
...solidPkgsConfig.ssr.noExternal,
313+
];
314+
config.resolve.external = [
315+
...(Array.isArray(config.resolve.external) ? config.resolve.external : []),
316+
...solidPkgsConfig.ssr.external,
317+
];
318+
}
319+
}
304320
},
305321

306322
configResolved(config) {

0 commit comments

Comments
 (0)