File tree 5 files changed +53
-4
lines changed
packages/vite/src/node/plugins
__tests__/sass-modern-compiler-build
sass-modern-compiler-build
5 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -2314,15 +2314,16 @@ const makeModernCompilerScssWorker = (
2314
2314
alias : Alias [ ] ,
2315
2315
_maxWorkers : number | undefined ,
2316
2316
) => {
2317
- let compiler : Sass . AsyncCompiler | undefined
2317
+ let compilerPromise : Promise < Sass . AsyncCompiler > | undefined
2318
2318
2319
2319
const worker : Awaited < ReturnType < typeof makeModernScssWorker > > = {
2320
2320
async run ( sassPath , data , options ) {
2321
2321
// need pathToFileURL for windows since import("D:...") fails
2322
2322
// https://github.com/nodejs/node/issues/31710
2323
2323
const sass : typeof Sass = ( await import ( pathToFileURL ( sassPath ) . href ) )
2324
2324
. default
2325
- compiler ??= await sass . initAsyncCompiler ( )
2325
+ compilerPromise ??= sass . initAsyncCompiler ( )
2326
+ const compiler = await compilerPromise
2326
2327
2327
2328
const sassOptions = { ...options } as Sass . StringOptions < 'async' >
2328
2329
sassOptions . url = pathToFileURL ( options . filename )
@@ -2373,8 +2374,8 @@ const makeModernCompilerScssWorker = (
2373
2374
} satisfies ScssWorkerResult
2374
2375
} ,
2375
2376
async stop ( ) {
2376
- compiler ?. dispose ( )
2377
- compiler = undefined
2377
+ ; ( await compilerPromise ) ?. dispose ( )
2378
+ compilerPromise = undefined
2378
2379
} ,
2379
2380
}
2380
2381
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