fix(css): reset render cache on renderStart (#14326)

This commit is contained in:
Bjorn Lu 2023-09-08 15:07:46 +08:00
parent fcaf7491f4
commit d334b3de8c
5 changed files with 58 additions and 1 deletions

View File

@ -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>()

View File

@ -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

View File

@ -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'
}

View File

@ -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'
}

View File

@ -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',
})