Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -1658,7 +1658,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) {
if (!resolved.builder?.sharedConfigBuild && resolved.environments.ssr) {
resolved.environments.ssr.build.emitAssets =
resolved.build.ssrEmitAssets || resolved.build.emitAssets
}
Expand Down
Loading