dart-sass
dart-sass copied to clipboard
Have a JS/TS API to have the same behavior as the command line
With the the command line, it's possible to use sass path/to/source:path/to/destination -s compressed --source-map --embed-sources (or with other options like watch for example).
Is it possible to have this in JS/TS API with the same behavior?
An example with types on what I imagine:
type Style = 'compressed' | 'expanded';
interface Options {
sourceMap: boolean;
style: Style;
embedSources: boolean;
watch: boolean;
// …
}
type RenderDirectory = (from: string, to: string, options: Partial<Options> = {}) => void;
type RenderDirectoryAsync = (from: string, to: string, options: Partial<Options> = {}) => Promise<void>;
interface Sass: { // Here is the augmentation of Sass
renderDirectory: RenderDirectory;
renderDirectoryAsync: RenderDirectoryAsync;
}
Example of usage:
sass.renderDirectory('path/to/source', 'path/to/destination', {
style: 'compressed',
sourceMap: true,
embedSources: true,
});
Motivations on why I need this: Because I use the directory rendering (currently available only with the command line) inside a program and I should use child_process to launch npx to start the sass execution and for a lot of reason there is some cases where npx isn't recognized.