MCPcopy
hub / github.com/vitejs/vite / manifestPlugin

Function manifestPlugin

packages/vite/src/node/plugins/manifest.ts:60–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60export function manifestPlugin(): Plugin {
61 const getState = perEnvironmentState(() => {
62 return {
63 manifest: {} as Manifest,
64 outputCount: 0,
65 reset() {
66 this.manifest = {}
67 this.outputCount = 0
68 },
69 }
70 })
71
72 return perEnvironmentPlugin('native:manifest', (environment) => {
73 if (!environment.config.build.manifest) return false
74
75 const root = environment.config.root
76 const outPath =
77 environment.config.build.manifest === true
78 ? '.vite/manifest.json'
79 : environment.config.build.manifest
80
81 const envs: Record<string, Environment> = {}
82 function getChunkName(chunk: OutputChunk) {
83 return (
84 getChunkOriginalFileName(chunk, root, false) ??
85 `_${path.basename(chunk.fileName)}`
86 )
87 }
88
89 return [
90 {
91 name: 'native:manifest-envs',
92 buildStart() {
93 envs[environment.name] = this.environment
94 },
95 },
96 nativeManifestPlugin({
97 root,
98 outPath,
99 isOutputOptionsForLegacyChunks:
100 environment.config.isOutputOptionsForLegacyChunks,
101 cssEntries() {
102 return Object.fromEntries(
103 [...cssEntriesMap.get(envs[environment.name])!.values()].map(
104 ({ name, referenceId }) => {
105 return [referenceId, name]
106 },
107 ),
108 )
109 },
110 }),
111 {
112 name: 'native:manifest-compatible',
113 generateBundle(_, bundle) {
114 const asset = bundle[outPath]
115 if (asset.type === 'asset') {
116 let manifest: Manifest | undefined
117 for (const output of Object.values(bundle)) {

Callers 1

resolveBuildPluginsFunction · 0.90

Calls 2

perEnvironmentStateFunction · 0.90
perEnvironmentPluginFunction · 0.85

Tested by

no test coverage detected