File tree Expand file tree Collapse file tree 5 files changed +53
-4
lines changed
packages/vite/src/node/plugins
__tests__/sass-modern-compiler-build
sass-modern-compiler-build Expand file tree Collapse file tree 5 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -2314,15 +2314,16 @@ const makeModernCompilerScssWorker = (
23142314 alias : Alias [ ] ,
23152315 _maxWorkers : number | undefined ,
23162316) => {
2317- let compiler : Sass . AsyncCompiler | undefined
2317+ let compilerPromise : Promise < Sass . AsyncCompiler > | undefined
23182318
23192319 const worker : Awaited < ReturnType < typeof makeModernScssWorker > > = {
23202320 async run ( sassPath , data , options ) {
23212321 // need pathToFileURL for windows since import("D:...") fails
23222322 // https://github.com/nodejs/node/issues/31710
23232323 const sass : typeof Sass = ( await import ( pathToFileURL ( sassPath ) . href ) )
23242324 . default
2325- compiler ??= await sass . initAsyncCompiler ( )
2325+ compilerPromise ??= sass . initAsyncCompiler ( )
2326+ const compiler = await compilerPromise
23262327
23272328 const sassOptions = { ...options } as Sass . StringOptions < 'async' >
23282329 sassOptions . url = pathToFileURL ( options . filename )
@@ -2373,8 +2374,8 @@ const makeModernCompilerScssWorker = (
23732374 } satisfies ScssWorkerResult
23742375 } ,
23752376 async stop ( ) {
2376- compiler ?. dispose ( )
2377- compiler = undefined
2377+ ; ( await compilerPromise ) ?. dispose ( )
2378+ compilerPromise = undefined
23782379 } ,
23792380 }
23802381
Original file line number Diff line number Diff line change 1+ import { expect , test } from 'vitest'
2+ import { findAssetFile , isBuild } from '~utils'
3+
4+ test . runIf ( isBuild ) ( 'sass modern compiler build multiple entries' , ( ) => {
5+ expect ( findAssetFile ( / e n t r y 1 / , 'sass-modern-compiler-build' ) )
6+ . toMatchInlineSnapshot ( `
7+ ".entry1{color:red}
8+ "
9+ ` )
10+ expect ( findAssetFile ( / e n t r y 2 / , 'sass-modern-compiler-build' ) )
11+ . toMatchInlineSnapshot ( `
12+ ".entry2{color:#00f}
13+ "
14+ ` )
15+ } )
Original file line number Diff line number Diff line change 1+ .entry1 {
2+ color : red ;
3+ }
Original file line number Diff line number Diff line change 1+ .entry2 {
2+ color : blue ;
3+ }
Original file line number Diff line number Diff line change 1+ import path from 'node:path'
2+ import { defineConfig } from 'vite'
3+
4+ export default defineConfig ( {
5+ build : {
6+ outDir : 'dist/sass-modern-compiler-build' ,
7+ rollupOptions : {
8+ input : {
9+ entry1 : path . join (
10+ import . meta. dirname ,
11+ 'sass-modern-compiler-build/entry1.scss' ,
12+ ) ,
13+ entry2 : path . join (
14+ import . meta. dirname ,
15+ 'sass-modern-compiler-build/entry2.scss' ,
16+ ) ,
17+ } ,
18+ } ,
19+ } ,
20+ css : {
21+ preprocessorOptions : {
22+ scss : {
23+ api : 'modern-compiler' ,
24+ } ,
25+ } ,
26+ } ,
27+ } )
You can’t perform that action at this time.
0 commit comments