Skip to content
/ vite Public

Commit d334b3d

Browse files
committedOct 3, 2023
fix(css): reset render cache on renderStart (#14326)
1 parent fcaf749 commit d334b3d

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed
 

‎packages/vite/src/node/plugins/css.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
406406
return {
407407
name: 'vite:css-post',
408408

409-
buildStart() {
409+
renderStart() {
410410
// Ensure new caches for every build (i.e. rebuilding in watch mode)
411411
pureCssChunks = new Set<RenderedChunk>()
412412
outputToExtractedCSSMap = new Map<NormalizedOutputOptions, string>()

‎playground/lib/__tests__/serve.ts

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export async function serve(): Promise<{ close(): Promise<void> }> {
6161
configFile: path.resolve(__dirname, '../vite.dyimport.config.js'),
6262
})
6363

64+
await build({
65+
root: rootDir,
66+
logLevel: 'warn', // output esbuild warns
67+
configFile: path.resolve(__dirname, '../vite.multiple-output.config.js'),
68+
})
69+
6470
await build({
6571
root: rootDir,
6672
logLevel: 'warn', // output esbuild warns
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// import file to test css build handling
2+
import './index.css'
3+
4+
export default async function message(sel) {
5+
document.querySelector(sel).textContent = 'success'
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// import file to test css build handling
2+
import './index.css'
3+
4+
export default async function message(sel) {
5+
document.querySelector(sel).textContent = 'success'
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import path from 'node:path'
2+
import { defineConfig } from 'vite'
3+
4+
const root = process.env.VITEST
5+
? path.resolve(__dirname, '../../playground-temp/lib')
6+
: __dirname
7+
8+
export default defineConfig({
9+
build: {
10+
lib: {
11+
// set multiple entrypoint to trigger css chunking
12+
entry: {
13+
main: path.resolve(__dirname, 'src/main-multiple-output.js'),
14+
sub: path.resolve(__dirname, 'src/sub-multiple-output.js'),
15+
},
16+
name: 'MyLib',
17+
},
18+
outDir: 'dist/multiple-output',
19+
rollupOptions: {
20+
// due to playground-temp, the `dir` needs to be relative to the resolvedRoot
21+
output: [
22+
{
23+
dir: path.resolve(root, 'dist/multiple-output/es'),
24+
format: 'es',
25+
entryFileNames: 'index.mjs',
26+
assetFileNames: 'assets/mylib.css',
27+
},
28+
{
29+
dir: path.resolve(root, 'dist/multiple-output/cjs'),
30+
format: 'cjs',
31+
entryFileNames: 'index.cjs',
32+
assetFileNames: 'assets/mylib.css',
33+
},
34+
],
35+
},
36+
cssCodeSplit: true,
37+
},
38+
cacheDir: 'node_modules/.vite-multiple-output',
39+
})

0 commit comments

Comments
 (0)
Please sign in to comment.