Skip to content

Commit

Permalink
feat: extract config.base in importAnalysisBuild.ts (#4096)
Browse files Browse the repository at this point in the history
  • Loading branch information
hex-ci committed Jul 13, 2021
1 parent b5ab77d commit ab59598
Showing 1 changed file with 7 additions and 4 deletions.
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
// @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

0 comments on commit ab59598

Please sign in to comment.