Skip to content

Commit

Permalink
feat: dedupe/preserveSymlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Apr 8, 2024
1 parent 0ea8be9 commit 3ba9214
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/preAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function preAliasPlugin(config: ResolvedConfig): Plugin {
}
}

// TODO: ?
function optimizeAliasReplacementForSSR(
id: string,
optimizeDeps: DepOptimizationOptions,
Expand Down
12 changes: 4 additions & 8 deletions packages/vite/src/node/ssr/fetchModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@ export async function fetchModule(
}

if (url[0] !== '.' && url[0] !== '/') {
const {
isProduction,
resolve: { dedupe, preserveSymlinks },
root,
ssr,
} = environment.config
const externalConditions = ssr.resolve?.externalConditions || []
const { isProduction, root } = environment.config
const { externalConditions, dedupe, preserveSymlinks } =
environment.options.resolve

const resolveOptions: InternalResolveOptionsWithOverrideConditions = {
mainFields: ['main'],
conditions: [],
externalConditions,
external: [], // TODO, should it be ssr.resolve.external?
external: [], // TODO, should it be environment.options.resolve.external?
noExternal: [],
overrideConditions: [...externalConditions, 'production', 'development'],
extensions: ['.js', '.cjs', '.json'],
Expand Down
15 changes: 6 additions & 9 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ async function instantiateModule(
urlStack: string[] = [],
fixStacktrace?: boolean,
): Promise<SSRModule> {
const moduleGraph = server.environments.ssr.moduleGraph
const environment = server.environments.ssr
const moduleGraph = environment.moduleGraph
const mod = await moduleGraph.ensureEntryFromUrl(url)

if (mod.ssrError) {
Expand All @@ -96,7 +97,7 @@ async function instantiateModule(
return mod.ssrModule
}
const result =
mod.transformResult || (await server.environments.ssr.transformRequest(url))
mod.transformResult || (await environment.transformRequest(url))
if (!result) {
// TODO more info? is this even necessary?
throw new Error(`failed to load module for ssr: ${url}`)
Expand Down Expand Up @@ -124,14 +125,10 @@ async function instantiateModule(
urlStack = urlStack.concat(url)
const isCircular = (url: string) => urlStack.includes(url)

const {
isProduction,
resolve: { dedupe, preserveSymlinks },
root,
ssr,
} = server.config
const { isProduction, root } = server.config

const externalConditions = ssr.resolve?.externalConditions || []
const { externalConditions, dedupe, preserveSymlinks } =
environment.options.resolve

const resolveOptions: NodeImportResolveOptions = {
mainFields: ['main'],
Expand Down

0 comments on commit 3ba9214

Please sign in to comment.