Skip to content

Commit

Permalink
chore: relocate to manifest only side-effects
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Sep 2, 2022
1 parent 7757787 commit 9f0ba41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 2 additions & 6 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import { FS_PREFIX } from '../constants'

export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g

export const duplicateAssets: OutputAsset[] = []

const rawRE = /(\?|&)raw(?:&|$)/
const urlRE = /(\?|&)url(?:&|$)/

const assetCache = new WeakMap<ResolvedConfig, Map<string, string>>()

const duplicateAssets: OutputAsset[] = []

const assetHashToFilenameMap = new WeakMap<
ResolvedConfig,
Map<string, string>
Expand Down Expand Up @@ -185,10 +185,6 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
},

generateBundle(_, bundle) {
duplicateAssets.forEach((asset) => {
bundle[asset.name!] = asset
})

// do not emit assets for SSR build
if (config.command === 'build' && config.build.ssr) {
for (const file in bundle) {
Expand Down
8 changes: 8 additions & 0 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ResolvedConfig } from '..'
import type { Plugin } from '../plugin'
import { normalizePath } from '../utils'
import { cssEntryFilesCache } from './css'
import { duplicateAssets } from './asset'

export type Manifest = Record<string, ManifestChunk>

Expand All @@ -16,6 +17,7 @@ export interface ManifestChunk {
isDynamicEntry?: boolean
imports?: string[]
dynamicImports?: string[]
isDuplicate?: true
}

export function manifestPlugin(config: ResolvedConfig): Plugin {
Expand Down Expand Up @@ -122,6 +124,12 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
}
}

duplicateAssets.forEach((asset) => {
const chunk = createAsset(asset)
chunk.isDuplicate = true
manifest[asset.name!] = chunk
})

outputCount++
const output = config.build.rollupOptions?.output
const outputLength = Array.isArray(output) ? output.length : 1
Expand Down

0 comments on commit 9f0ba41

Please sign in to comment.