@@ -2,20 +2,20 @@ import {dirname, parse, relative, resolve, sep} from 'path'
2
2
import fs , { readFileSync } from 'fs'
3
3
import { createResolver , fileSyntax , sourceMappingURL } from './utils'
4
4
import { PartialMessage } from 'esbuild'
5
- import * as sass from 'sass'
6
- import { ImporterResult } from 'sass'
5
+ import * as sass from 'sass-embedded '
6
+ import { ImporterResult , initAsyncCompiler } from 'sass-embedded '
7
7
import { fileURLToPath , pathToFileURL } from 'url'
8
8
import { SassPluginOptions } from './index'
9
9
10
- export type RenderSync = ( path : string ) => RenderResult
10
+ export type RenderSync = ( path : string ) => Promise < RenderResult >
11
11
12
12
export type RenderResult = {
13
13
cssText : string
14
14
watchFiles : string [ ]
15
15
warnings ?: PartialMessage [ ]
16
16
}
17
17
18
- export function createRenderer ( options : SassPluginOptions = { } , sourcemap : boolean ) : RenderSync {
18
+ export async function createRenderer ( options : SassPluginOptions = { } , sourcemap : boolean ) : Promise < RenderSync > {
19
19
20
20
const loadPaths = options . loadPaths !
21
21
const resolveModule = createResolver ( options , loadPaths )
@@ -61,10 +61,12 @@ export function createRenderer(options: SassPluginOptions = {}, sourcemap: boole
61
61
62
62
const sepTilde = `${ sep } ~`
63
63
64
+ const compiler = await initAsyncCompiler ( ) ;
65
+
64
66
/**
65
67
* renderSync
66
68
*/
67
- return function ( path : string ) : RenderResult {
69
+ return async function ( path : string ) : Promise < RenderResult > {
68
70
69
71
const basedir = dirname ( path )
70
72
@@ -112,7 +114,7 @@ export function createRenderer(options: SassPluginOptions = {}, sourcemap: boole
112
114
css,
113
115
loadedUrls,
114
116
sourceMap
115
- } = sass . compileString ( source , {
117
+ } = await compiler . compileStringAsync ( source , {
116
118
sourceMapIncludeSources : true ,
117
119
...options ,
118
120
logger,
0 commit comments