Skip to content

Commit

Permalink
chore: remove changes to SSR/optimizeDeps, TBD in another PR
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jul 4, 2022
1 parent 81b3992 commit 8861550
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import colors from 'picocolors'
import type { BuildOptions as EsbuildBuildOptions } from 'esbuild'
import { build } from 'esbuild'
import { init, parse } from 'es-module-lexer'
import { createFilter } from '@rollup/pluginutils'
import type { ResolvedConfig } from '../config'
import {
arraify,
createDebugger,
emptyDir,
flattenId,
Expand Down Expand Up @@ -258,9 +260,30 @@ export async function optimizeServerSsrDeps(
return cachedMetadata
}

let alsoInclude: string[] | undefined
let noExternalFilter: ((id: unknown) => boolean) | undefined

const noExternal = config.ssr?.noExternal
if (noExternal) {
alsoInclude = arraify(noExternal).filter(
(ne) => typeof ne === 'string'
) as string[]
noExternalFilter =
noExternal === true
? (dep: unknown) => false
: createFilter(noExternal, config.optimizeDeps?.exclude, {
resolve: false
})
}

const deps: Record<string, string> = {}

await addManuallyIncludedOptimizeDeps(deps, config)
await addManuallyIncludedOptimizeDeps(
deps,
config,
alsoInclude,
noExternalFilter
)

const depsInfo = toDiscoveredDependencies(config, deps, true)

Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
if (moduleListContains(config.optimizeDeps?.exclude, url)) {
if (depsOptimizer) {
await depsOptimizer.scanProcessing

// if the dependency encountered in the optimized file was excluded from the optimization
// the dependency needs to be resolved starting from the original source location of the optimized file
// because starting from node_modules/.vite will not find the dependency if it was not hoisted
Expand Down Expand Up @@ -531,6 +532,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
}

if (!isDynamicImport) {
// for pre-transforming
staticImportedUrls.add({ url: urlWithoutBase, id: resolvedId })
}
} else if (!importer.startsWith(clientDir) && !ssr) {
Expand Down

0 comments on commit 8861550

Please sign in to comment.