compileString
- compile
String(source:string,options?:StringOptions<"sync">):CompileResult - Dart Sass
- since 1.45.0
- Node Sass
- ✗
Compatibility:Synchronously compiles a stylesheet whose contents is
source
toCSS. If itsucceeds it returns aCompileResult, and if it fails it throws anException.This only allows synchronousImporters andCustomFunctions.
⚠️ Heads up!
When using thesass-embedded npm package for singlecompilations,compileStringAsync is almost always faster thancompileString, due to the overhead of emulating synchronousmessaging with worker threads and concurrent compilations being blocked onmain thread.
If you are running multiple compilations with thesass-embedded npmpackage, using aCompiler will provide some speed improvements overthe module-level methods, and anAsyncCompiler will be much faster.
Example
constsass =require('sass');
constresult =sass.compileString(`
h1 {
font-size: 40px;
code {
font-face: Roboto Mono;
}
}`);
console.log(result.css);Parameters
source:string
Optional
options:StringOptions<"sync">
ReturnsCompileResult
- Defined injs-api-doc/compile.d.ts:236