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 1 commit
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
8 changes: 5 additions & 3 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,7 +44,8 @@ function preload(baseModule: () => Promise<{}>, deps?: string[]) {

return Promise.all(
deps.map((dep) => {
dep = `__VITE_PRELOAD_BASE__${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 @@ -92,7 +94,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {

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

Expand Down