Skip to content

Commit

Permalink
fix(css): reset render cache on renderStart (#14326)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 3, 2023
1 parent fcaf749 commit d334b3d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
return {
name: 'vite:css-post',

buildStart() {
renderStart() {
// Ensure new caches for every build (i.e. rebuilding in watch mode)
pureCssChunks = new Set<RenderedChunk>()
outputToExtractedCSSMap = new Map<NormalizedOutputOptions, string>()
Expand Down
6 changes: 6 additions & 0 deletions playground/lib/__tests__/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export async function serve(): Promise<{ close(): Promise<void> }> {
configFile: path.resolve(__dirname, '../vite.dyimport.config.js'),
})

await build({
root: rootDir,
logLevel: 'warn', // output esbuild warns
configFile: path.resolve(__dirname, '../vite.multiple-output.config.js'),
})

await build({
root: rootDir,
logLevel: 'warn', // output esbuild warns
Expand Down
6 changes: 6 additions & 0 deletions playground/lib/src/main-multiple-output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// import file to test css build handling
import './index.css'

export default async function message(sel) {
document.querySelector(sel).textContent = 'success'
}
6 changes: 6 additions & 0 deletions playground/lib/src/sub-multiple-output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// import file to test css build handling
import './index.css'

export default async function message(sel) {
document.querySelector(sel).textContent = 'success'
}
39 changes: 39 additions & 0 deletions playground/lib/vite.multiple-output.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'node:path'
import { defineConfig } from 'vite'

const root = process.env.VITEST
? path.resolve(__dirname, '../../playground-temp/lib')
: __dirname

export default defineConfig({
build: {
lib: {
// set multiple entrypoint to trigger css chunking
entry: {
main: path.resolve(__dirname, 'src/main-multiple-output.js'),
sub: path.resolve(__dirname, 'src/sub-multiple-output.js'),
},
name: 'MyLib',
},
outDir: 'dist/multiple-output',
rollupOptions: {
// due to playground-temp, the `dir` needs to be relative to the resolvedRoot
output: [
{
dir: path.resolve(root, 'dist/multiple-output/es'),
format: 'es',
entryFileNames: 'index.mjs',
assetFileNames: 'assets/mylib.css',
},
{
dir: path.resolve(root, 'dist/multiple-output/cjs'),
format: 'cjs',
entryFileNames: 'index.cjs',
assetFileNames: 'assets/mylib.css',
},
],
},
cssCodeSplit: true,
},
cacheDir: 'node_modules/.vite-multiple-output',
})

0 comments on commit d334b3d

Please sign in to comment.