Skip to content

Commit

Permalink
fix: assets with vite
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenlu committed Mar 9, 2023
1 parent 16b49d2 commit bcb4253
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/plugins/rollup/src/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ import { getBuildEnv } from '@perfsee/plugin-utils'

import { recursivelyFindEntryChunks } from './util'

interface ChunkMetadata {
importedAssets: Set<string>
importedCss: Set<string>
}

declare module 'rollup' {
interface OutputChunk {
viteMetadata?: ChunkMetadata
}
}

const isChunk = (output: OutputAsset | OutputChunk): output is OutputChunk => output.type === 'chunk'

let id = 0
Expand Down Expand Up @@ -136,11 +147,10 @@ export function rollupOutput2WebpackStats(this: PluginContext, outputBundle: Out
importChunk.parents.includes(currentChunk.id) || importChunk.parents.push(currentChunk.id)
})

currentChunk.files = union(
currentChunk.files,
allImports,
assetsEntries.map(([path]) => path),
)
const assetFiles = chunk.viteMetadata
? Array.from(chunk.viteMetadata.importedAssets.values())
: assetsEntries.map(([path]) => path)
currentChunk.files = union(currentChunk.files, allImports, assetFiles)
})

const assetsByChunkName = Object.fromEntries([...chunksMap.entries()].map(([name, { files }]) => [name, files]))
Expand Down

0 comments on commit bcb4253

Please sign in to comment.