Skip to content

Commit b48363c

Browse files
author
Stanislav Lashmanov
committed
feat(build): provide names for asset entrypoints
1 parent a50b21b commit b48363c

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

packages/vite/src/node/__tests__/build.spec.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,10 @@ test('watch rebuild manifest', async (ctx) => {
10491049
client: {
10501050
build: {
10511051
rollupOptions: {
1052-
input: '/entry.js',
1052+
input: {
1053+
entry: '/entry.js',
1054+
cssEntry: '/entry.css',
1055+
},
10531056
},
10541057
},
10551058
},
@@ -1059,19 +1062,19 @@ test('watch rebuild manifest', async (ctx) => {
10591062
},
10601063
})
10611064

1062-
function getManifestKeys(output: RollupOutput) {
1063-
return Object.keys(
1064-
JSON.parse(
1065-
(output.output.find((o) => o.fileName === '.vite/manifest.json') as any)
1066-
.source,
1067-
),
1068-
)
1065+
function getManifest(output: RollupOutput) {
1066+
const { source } = output.output.find(
1067+
(o) => o.fileName === '.vite/manifest.json',
1068+
) as any
1069+
return JSON.parse(source)
10691070
}
10701071

10711072
const result = await builder.build(builder.environments.client)
1072-
expect(getManifestKeys(result as RollupOutput)).toMatchInlineSnapshot(`
1073+
expect(Object.keys(getManifest(result as RollupOutput)))
1074+
.toMatchInlineSnapshot(`
10731075
[
10741076
"dep.js",
1077+
"entry.css",
10751078
"entry.js",
10761079
]
10771080
`)
@@ -1087,11 +1090,18 @@ test('watch rebuild manifest', async (ctx) => {
10871090
})
10881091

10891092
const result2 = await builder.build(builder.environments.client)
1090-
expect(getManifestKeys(result2 as RollupOutput)).toMatchInlineSnapshot(`
1093+
const manifest = getManifest(result2 as RollupOutput)
1094+
expect(Object.keys(manifest)).toMatchInlineSnapshot(`
10911095
[
1096+
"entry.css",
10921097
"entry.js",
10931098
]
10941099
`)
1100+
expect(manifest['entry.css'].names).toMatchInlineSnapshot(`
1101+
[
1102+
"cssEntry.css",
1103+
]
1104+
`)
10951105
})
10961106

10971107
/**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: red;
3+
}

packages/vite/src/node/plugins/manifest.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ManifestChunk {
2121
assets?: string[]
2222
isEntry?: boolean
2323
name?: string
24+
names?: string[]
2425
isDynamicEntry?: boolean
2526
imports?: string[]
2627
dynamicImports?: string[]
@@ -127,7 +128,10 @@ export function manifestPlugin(): Plugin {
127128
file: asset.fileName,
128129
src,
129130
}
130-
if (isEntry) manifestChunk.isEntry = true
131+
if (isEntry) {
132+
manifestChunk.isEntry = true
133+
manifestChunk.names = asset.names
134+
}
131135
return manifestChunk
132136
}
133137

0 commit comments

Comments
 (0)