Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,73 @@ test.for([true, false])(
},
)

test('sharedConfigBuild and emitAssets', async () => {
const root = resolve(__dirname, 'fixtures/shared-config-build/emitAssets')
const builder = await createBuilder({
root,
logLevel: 'warn',
configFile: false,
environments: {
client: {
build: {
outDir: './dist/client',
emitAssets: true,
rollupOptions: {
input: '/entry.js',
},
},
},
ssr: {
build: {
outDir: './dist/ssr',
emitAssets: true,
rollupOptions: {
input: '/entry.js',
},
},
},
custom: {
build: {
outDir: './dist/custom',
emitAssets: true,
rollupOptions: {
input: '/entry.js',
},
},
},
},
builder: {
sharedConfigBuild: true,
},
})

expect(
['client', 'ssr', 'custom'].map(
(name) => builder.environments[name].config.build.emitAssets,
),
).toEqual([true, true, true])

await builder.buildApp()

expect(
await Promise.all(
['client', 'ssr', 'custom'].map((name) =>
fsp.readdir(
resolve(
root,
builder.environments[name].config.build.outDir,
'assets',
),
),
),
),
).toEqual([
expect.arrayContaining([expect.stringMatching(/\.css$/)]),
expect.arrayContaining([expect.stringMatching(/\.css$/)]),
expect.arrayContaining([expect.stringMatching(/\.css$/)]),
])
})

test('adjust worker build error for worker.format', async () => {
try {
await build({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './test.css'
console.log('entry')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: orange;
}
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ export async function resolveConfig(
// For backward compat, set ssr environment build.emitAssets with the same value as build.ssrEmitAssets that might be changed in configResolved hook
// https://github.com/vikejs/vike/blob/953614cea7b418fcc0309b5c918491889fdec90a/vike/node/plugin/plugins/buildConfig.ts#L67
if (resolved.environments.ssr) {
resolved.environments.ssr.build.emitAssets =
resolved.environments.ssr.build.emitAssets ||=
Copy link
Member

@sapphi-red sapphi-red Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This backward compat only makes sense with builder.sharedConfigBuild: false because only in that case build.* and environments.ssr.build.* should be synced.
So I think, instead, we can skip this code when sharedConfigBuild is enabled:

if (!sharedConfigBuild && resolved.environments.ssr) {
  resolved.environments.ssr.build.emitAssets = resolved.build.ssrEmitAssets || resolved.build.emitAssets
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds simpler. Thanks!

resolved.build.ssrEmitAssets || resolved.build.emitAssets
}

Expand Down
Loading