Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extract config.base in importAnalysisBuild.ts #4096

Merged
merged 2 commits into from Jul 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Expand Up @@ -15,9 +15,10 @@ import { transformImportGlob } from '../importGlob'
export const isModernFlag = `__VITE_IS_MODERN__`
export const preloadMethod = `__vitePreload`
export const preloadMarker = `__VITE_PRELOAD__`
export const preloadBaseMarker = `__VITE_PRELOAD_BASE__`

const preloadHelperId = 'vite/preload-helper'
const preloadCode = `let scriptRel;const seen = {};export const ${preloadMethod} = ${preload.toString()}`
const preloadCode = `let scriptRel;const seen = {};const base = '${preloadBaseMarker}';export const ${preloadMethod} = ${preload.toString()}`
const preloadMarkerRE = new RegExp(`"${preloadMarker}"`, 'g')

/**
Expand All @@ -43,6 +44,8 @@ function preload(baseModule: () => Promise<{}>, deps?: string[]) {

return Promise.all(
deps.map((dep) => {
// @ts-ignore
dep = `${base}${dep}`
// @ts-ignore
if (dep in seen) return
hex-ci marked this conversation as resolved.
Show resolved Hide resolved
// @ts-ignore
Expand Down Expand Up @@ -91,7 +94,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {

load(id) {
if (id === preloadHelperId) {
return preloadCode
return preloadCode.replace(preloadBaseMarker, config.base)
}
},

Expand Down Expand Up @@ -245,11 +248,11 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
analyzed.add(filename)
const chunk = bundle[filename] as OutputChunk | undefined
if (chunk) {
deps.add(config.base + chunk.fileName)
deps.add(chunk.fileName)
const cssFiles = chunkToEmittedCssFileMap.get(chunk)
if (cssFiles) {
cssFiles.forEach((file) => {
deps.add(config.base + file)
deps.add(file)
})
}
chunk.imports.forEach(addDeps)
Expand Down