Skip to content

Commit

Permalink
feat: library mode does not include preload
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jul 19, 2021
1 parent e47a6f2 commit 5cddff9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/vite/src/node/importGlob.ts
Expand Up @@ -15,7 +15,7 @@ export async function transformImportGlob(
importIndex: number,
root: string,
normalizeUrl?: (url: string, pos: number) => Promise<[string, string]>,
ssr = false
preload = true
): Promise<{
importsString: string
imports: string[]
Expand Down Expand Up @@ -87,7 +87,7 @@ export async function transformImportGlob(
entries += ` ${JSON.stringify(file)}: ${identifier},`
} else {
let imp = `import(${JSON.stringify(importee)})`
if (!normalizeUrl && !ssr) {
if (!normalizeUrl && preload) {
imp =
`(${isModernFlag}` +
`? ${preloadMethod}(()=>${imp},"${preloadMarker}")` +
Expand Down
7 changes: 4 additions & 3 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Expand Up @@ -82,6 +82,7 @@ function preload(baseModule: () => Promise<{}>, deps?: string[]) {
*/
export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
const ssr = !!config.build.ssr
const insertPreload = !(ssr || !!config.build.lib)

return {
name: 'vite:import-analysis',
Expand Down Expand Up @@ -145,7 +146,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
index,
config.root,
undefined,
ssr
insertPreload
)
str().prepend(importsString)
str().overwrite(expStart, endIndex, exp)
Expand All @@ -155,7 +156,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
continue
}

if (dynamicIndex > -1 && !ssr) {
if (dynamicIndex > -1 && insertPreload) {
needPreloadHelper = true
const dynamicEnd = source.indexOf(`)`, end) + 1
const original = source.slice(dynamicIndex, dynamicEnd)
Expand All @@ -166,7 +167,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {

if (
needPreloadHelper &&
!ssr &&
insertPreload &&
!source.includes(`const ${preloadMethod} =`)
) {
str().prepend(`import { ${preloadMethod} } from "${preloadHelperId}";`)
Expand Down

0 comments on commit 5cddff9

Please sign in to comment.