Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 8, 2023
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
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 @@ -405,7 +405,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',
})
Loading