makeScssWorker() — vite Function Reference
Architecture documentation for the makeScssWorker() function in css.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 788c7102_1f9e_48db_0312_d3566b067276["makeScssWorker()"] c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"] 788c7102_1f9e_48db_0312_d3566b067276 -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224 0a163673_dac2_220c_2b8a_a489f9a38632["scssProcessor()"] 0a163673_dac2_220c_2b8a_a489f9a38632 -->|calls| 788c7102_1f9e_48db_0312_d3566b067276 f9a13b61_758d_6973_4d25_637ddaa2a22f["url()"] 788c7102_1f9e_48db_0312_d3566b067276 -->|calls| f9a13b61_758d_6973_4d25_637ddaa2a22f 1479899a_5d18_ab3c_da35_d44505504960["cleanScssBugUrl()"] 788c7102_1f9e_48db_0312_d3566b067276 -->|calls| 1479899a_5d18_ab3c_da35_d44505504960 5b519ec5_dd2f_e06c_4b7f_2007d9f5d884["rebaseUrls()"] 788c7102_1f9e_48db_0312_d3566b067276 -->|calls| 5b519ec5_dd2f_e06c_4b7f_2007d9f5d884 bff62ce1_58a6_b7b5_ef28_a3e2a2bc0779["load()"] 788c7102_1f9e_48db_0312_d3566b067276 -->|calls| bff62ce1_58a6_b7b5_ef28_a3e2a2bc0779 style 788c7102_1f9e_48db_0312_d3566b067276 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/css.ts lines 2487–2595
const makeScssWorker = (
environment: PartialEnvironment,
resolvers: CSSAtImportResolvers,
_maxWorkers: number | undefined,
) => {
let compilerPromise: Promise<Sass.AsyncCompiler> | undefined
// we use the compiler api provided by sass
// instead of creating a worker pool on our own
type WorkerType = InstanceType<
typeof WorkerWithFallback<
[
sassPath: string,
data: string,
// additionalData can a function that is not cloneable but it won't be used
options: SassStylePreprocessorInternalOptions & {
additionalData: undefined
},
],
ScssWorkerResult
>
>
const worker: WorkerType = {
async run(sassPath, data, options) {
const sass: typeof Sass = await import(sassPath)
compilerPromise ??= sass.initAsyncCompiler()
const compiler = await compilerPromise
const sassOptions = { ...options } as Sass.StringOptions<'async'>
sassOptions.url = pathToFileURL(options.filename)
sassOptions.sourceMap = options.enableSourcemap
const skipRebaseUrls = (unquotedUrl: string, rawUrl: string) => {
const isQuoted = rawUrl[0] === '"' || rawUrl[0] === "'"
// matches `url($foo)`
if (!isQuoted && unquotedUrl[0] === '$') {
return true
}
// matches `url(#{foo})` and `url('#{foo}')`
return unquotedUrl.startsWith('#{')
}
const internalImporter: Sass.Importer<'async'> = {
async canonicalize(url, context) {
const importer = context.containingUrl
? fileURLToPath(context.containingUrl)
: options.filename
const resolved = await resolvers.sass(
environment,
url,
cleanScssBugUrl(importer),
)
if (
resolved &&
(resolved.endsWith('.css') ||
resolved.endsWith('.scss') ||
resolved.endsWith('.sass'))
) {
return pathToFileURL(resolved)
}
return null
},
async load(canonicalUrl) {
const ext = path.extname(canonicalUrl.pathname)
let syntax: Sass.Syntax = 'scss'
if (ext === '.sass') {
syntax = 'indented'
} else if (ext === '.css') {
syntax = 'css'
}
const result = await rebaseUrls(
environment,
fileURLToPath(canonicalUrl),
options.filename,
resolvers.sass,
skipRebaseUrls,
)
const contents =
result.contents ?? (await fsp.readFile(result.file, 'utf-8'))
return { contents, syntax, sourceMapUrl: canonicalUrl }
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does makeScssWorker() do?
makeScssWorker() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is makeScssWorker() defined?
makeScssWorker() is defined in packages/vite/src/node/plugins/css.ts at line 2487.
What does makeScssWorker() call?
makeScssWorker() calls 4 function(s): cleanScssBugUrl, load, rebaseUrls, url.
What calls makeScssWorker()?
makeScssWorker() is called by 1 function(s): scssProcessor.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free