Skip to content

Commit 5c5efe4

Browse files
hi-ogawapatak-dev
andauthored
fix(v6): fix ssrEmitAssets compat (#16480)
Co-authored-by: patak-dev <matias.capeletto@gmail.com>
1 parent d4b155c commit 5c5efe4

File tree

5 files changed

+89
-1
lines changed

5 files changed

+89
-1
lines changed

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import colors from 'picocolors'
44
import { describe, expect, test, vi } from 'vitest'
55
import type { OutputChunk, OutputOptions, RollupOutput } from 'rollup'
66
import type { LibraryFormats, LibraryOptions } from '../build'
7-
import { build, resolveBuildOutputs, resolveLibFilename } from '../build'
7+
import {
8+
build,
9+
createViteBuilder,
10+
resolveBuildOutputs,
11+
resolveLibFilename,
12+
} from '../build'
813
import type { Logger } from '../logger'
914
import { createLogger } from '../logger'
1015

@@ -576,6 +581,65 @@ describe('resolveBuildOutputs', () => {
576581
),
577582
)
578583
})
584+
585+
test('ssrEmitAssets', async () => {
586+
const result = await build({
587+
root: resolve(__dirname, 'fixtures/emit-assets'),
588+
logLevel: 'silent',
589+
build: {
590+
ssr: true,
591+
ssrEmitAssets: true,
592+
rollupOptions: {
593+
input: {
594+
index: '/entry',
595+
},
596+
},
597+
},
598+
})
599+
expect(result).toMatchObject({
600+
output: [
601+
{
602+
fileName: 'index.mjs',
603+
},
604+
{
605+
fileName: expect.stringMatching(/assets\/index-\w*\.css/),
606+
},
607+
],
608+
})
609+
})
610+
611+
test('emitAssets', async () => {
612+
const builder = await createViteBuilder(
613+
{},
614+
{
615+
root: resolve(__dirname, 'fixtures/emit-assets'),
616+
environments: {
617+
ssr: {
618+
build: {
619+
ssr: true,
620+
emitAssets: true,
621+
rollupOptions: {
622+
input: {
623+
index: '/entry',
624+
},
625+
},
626+
},
627+
},
628+
},
629+
},
630+
)
631+
const result = await builder.build(builder.environments.ssr)
632+
expect(result).toMatchObject({
633+
output: [
634+
{
635+
fileName: 'index.mjs',
636+
},
637+
{
638+
fileName: expect.stringMatching(/assets\/index-\w*\.css/),
639+
},
640+
],
641+
})
642+
})
579643
})
580644

581645
/**
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.css-module {
2+
background: rgb(200, 250, 250);
3+
padding: 20px;
4+
width: 200px;
5+
border: 1px solid gray;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#css-normal {
2+
background: rgb(250, 250, 200);
3+
padding: 20px;
4+
width: 200px;
5+
border: 1px solid gray;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import './css-normal.css'
2+
import cssModule from './css-module.module.css'
3+
4+
export default function Page() {
5+
console.log(cssModule)
6+
}

packages/vite/src/node/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,12 @@ export async function resolveConfig(
901901
}
902902
}
903903

904+
if (config.build?.ssrEmitAssets !== undefined) {
905+
configEnvironmentsSsr ??= {}
906+
configEnvironmentsSsr.build ??= {}
907+
configEnvironmentsSsr.build.emitAssets = config.build.ssrEmitAssets
908+
}
909+
904910
// The client and ssr environment configs can't be removed by the user in the config hook
905911
if (
906912
!config.environments ||

0 commit comments

Comments
 (0)