Options for Sass compilation.

Hierarchy

Properties - Input

loadPaths?: string[]

Paths in which to look for stylesheets loaded by rules like @use and @import.

A load path loadPath is equivalent to the following FileImporter:

{
findFileUrl(url) {
// Load paths only support relative URLs.
if (/^[a-z]+:/i.test(url)) return null;
return new URL(url, pathToFileURL(loadPath));
}
}

Properties - Messages

alertAscii?: boolean

If this is true, the compiler will exclusively use ASCII characters in its error and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.

Default Value

false

alertColor?: boolean

If this is true, the compiler will use ANSI color escape codes in its error and warning messages. If it's false, it won't use these. If it's undefined, the compiler will determine whether or not to use colors depending on whether the user is using an interactive terminal.

logger?: Logger

An object to use to handle warnings and/or debug messages from Sass.

By default, Sass emits warnings and debug messages to standard error, but if Logger.warn or Logger.debug is set, this will invoke them instead.

The special value Logger.silent can be used to easily silence all messages.

quietDeps?: boolean

If this option is set to true, Sass won’t print warnings that are caused by dependencies. A “dependency” is defined as any file that’s loaded through loadPaths or importers. Stylesheets that are imported relative to the entrypoint are not considered dependencies.

This is useful for silencing deprecation warnings that you can’t fix on your own. However, please also notify your dependencies of the deprecations so that they can get fixed as soon as possible!

Heads up! If compileString or compileStringAsync is called without StringOptionsWithoutImporter.url, all stylesheets it loads will be considered dependencies. Since it doesn’t have a path of its own, everything it loads is coming from a load path rather than a relative import.

Default Value

false

verbose?: boolean

By default, Dart Sass will print only five instances of the same deprecation warning per compilation to avoid deluging users in console noise. If you set verbose to true, it will instead print every deprecation warning it encounters.

Default Value

false

Properties - Other

add?: boolean

should Autoprefixer add prefixes.

alwaysStat?: boolean

If relying upon the fs.Stats object that may get passed with add, addDir, and change events, set this to true to ensure it is provided even in cases where it wasn't already available from the underlying watch events.

atomic?: number | boolean

true if useFsEvents and usePolling are false). Automatically filters out artifacts that occur when using editors that use "atomic writes" instead of writing directly to the source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a change event rather than unlink then add. If the default of 100 ms does not work well for you, you can override it by setting atomic to a custom value, in milliseconds.

autoprefixer?: boolean

Specifies whether to enable autoprefixer for vendor prefixing.

awaitWriteFinish?: boolean | AwaitWriteFinishOptions

can be set to an object in order to adjust timing params:

baseDir?: string
binaryInterval?: number

Interval of file system polling for binary files. ([see list of binary extensions](https://gi thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))

browser?: string | string[]

The browser(s) to open Default: default

callbacks?: CallbacksOptions

Register callbacks via a regular option - this can be used to get access the Browsersync instance in situations where you cannot provide a callback via the normal API (for example, in a Gruntfile)

This 'ready' callback can be used to access the Browsersync instance

cascade?: boolean

should Autoprefixer use Visual Cascade, if CSS is uncompressed

clientEvents?: string[]

¯_(ツ)_/¯ Best guess, when ghostMode (or SocketIO?) is setup the events listed here will be emitted and able to hook into.

codeSync?: boolean

Send file-change events to the browser Default: true

cors?: boolean

Add HTTP access control (CORS) headers to assets served by Browsersync. Default: false Note: Requires at least version 2.16.0.

cssOutputPath?: string

Specify the path where the compiled CSS file should be generated.

cwd?: string

Current working directory

depth?: number

If set, limits how many levels of subdirectories will be traversed.

directories?: string[]

The directories to watch for changes.

disableGlobbing?: boolean

If set to true then the strings passed to .watch() and .add() are treated as literal path names, even if they look like globs. Default: false.

env?: string

environment for Browserslist

excludeFileTypes?: string[]

¯_(ツ)_/¯

excludePaths?: RegExp

Regular expression to exclude paths from Sass compilation.

extensions?: string[]

The file extensions to include when watching for changes.

files?: string | (string | object | FileCallback)[]

Browsersync can watch your files as you work. Changes you make will either be injected into the page (CSS & images) or will cause all browsers to do a full-page refresh. See anymatch for more information on glob patterns. Default: false

flexbox?: boolean | "no-2009"

should Autoprefixer add prefixes for flexbox properties

followSymlinks?: boolean

When false, only the symlinks themselves will be watched for changes instead of following the link references and bubbling events through the link's path.

ghostMode?: boolean | GhostOptions

Clicks, Scrolls & Form inputs on any device will be mirrored to all others. clicks - Default: true scroll - Default: true forms - Default: true

grid?: boolean | GridValue

should Autoprefixer add IE 10-11 prefixes for Grid Layout properties

host?: string

Override host detection if you know the correct IP to use

httpModule?: string

Override http module to allow using 3rd party server modules (such as http2).

https?: boolean | HttpsOptions

Enable https for localhost development. Note: This may not be needed for proxy option as it will try to infer from your target url. Note: If privacy error is encountered please see HttpsOptions below, setting those will resolve. Note: Requires at least version 1.3.0.

ignore?: string[]

Patterns for any watchers to ignore. Anything provided here will end up inside 'watchOptions.ignored'.

ignoreInitial?: boolean

If set to false then add/addDir events are also emitted for matching paths while instantiating the watching as chokidar discovers these file paths (before the ready event).

ignorePermissionErrors?: boolean

Indicates whether to watch files that don't have read permissions if possible. If watching fails due to EPERM or EACCES with this set to true, the errors will be suppressed silently.

ignoreUnknownVersions?: boolean

do not raise error on unknown browser version in Browserslist config.

ignored?: AnymatchMatcher

(anymatch-compatible definition) Defines files/paths to be ignored. The whole relative or absolute path is tested, not just filename. If a function with two arguments is provided, it gets called twice per path - once with a single argument (the path), second time with two arguments (the path and the fs.Stats object of that path).

importPaths?: string[]

Additional import paths to resolve Sass imports.

injectChanges?: boolean

Whether to inject changes (rather than a page refresh) Default: true

injectFileTypes?: string[]

¯_(ツ)_/¯

interval?: number

Interval of file system polling.

listen?: string

Specify a host to listen on. Use this if you want to prevent binding to all interfaces.

Note: When you specify this option, it overrides the 'host' option

localOnly?: boolean

Support environments where dynamic hostnames are not required (ie: electron).

logConnections?: boolean

Whether or not to log connections Default: false

logFileChanges?: boolean

Whether or not to log information about changed files Default: false

logLevel?: LogLevel

Can be either "info", "debug", "warn", or "silent" Default: info

logPrefix?: string

Change the console logging prefix. Useful if you're creating your own project based on Browsersync Default: BS Note: Requires at least version 1.5.1.

logSnippet?: boolean

Log the snippet to the console when you're in snippet mode (no proxy/server) Default: true Note: Requires at least version 1.5.2.

middleware?: MiddlewareHandler | PerRouteMiddleware | (MiddlewareHandler | PerRouteMiddleware)[]

Functions or actual plugins used as middleware.

minify?: boolean

Whether to minify the client script Default: true

notify?: boolean

The small pop-over notifications in the browser are not always needed/wanted. Default: true

online?: boolean

Some features of Browsersync (such as xip & tunnel) require an internet connection, but if you're working offline, you can reduce start-up time by setting this option to false

open?: boolean | OpenOptions

Default: true Decide which URL to open automatically when Browsersync starts. Defaults to "local" if none set. Can be true, local, external, ui, ui-external, tunnel or false

overrideBrowserslist?: string | string[]

list of queries for target browsers. Try to not use it. The best practice is to use .browserslistrc config or browserslist key in package.json to share target browsers with Babel, ESLint and Stylelint

persistent?: boolean

Indicates whether the process should continue to run as long as files are being watched. If set to false when using fsevents to watch, no more events will be emitted after ready, even if the process continues to run.

plugins?: any[]

User provided plugins Default: [] Note: Requires at least version 2.6.0.

port?: number

Use a specific port (instead of the one auto-detected by Browsersync) Default: 3000

proxy?: string | ProxyOptions

Proxy an EXISTING vhost. Browsersync will wrap your vhost with a proxy URL to view your site. Passing only a URL as a string equates to passing only target property of ProxyOptions type. target - Default: undefined ws - Default: undefined middleware - Default: undefined reqHeaders - Default: undefined proxyRes - Default: undefined (http.ServerResponse if expecting single parameter) proxyReq - Default: undefined

reloadDebounce?: number

Restrict the frequency in which browser:reload events can be emitted to connected clients Default: 0 Note: Requires at least version 2.6.0.

reloadDelay?: number

Time, in milliseconds, to wait before instructing the browser to reload/inject following a file change event Default: 0

reloadOnRestart?: boolean

Reload each browser when Browsersync is restarted. Default: false

reloadThrottle?: number

Emit only the first event during sequential time windows of a specified duration. Note: Requires at least version 2.13.0.

remove?: boolean

should Autoprefixer [remove outdated] prefixes

rewriteRules?: boolean | RewriteRules[]

Add additional HTML rewriting rules. Default: false Note: Requires at least version 2.4.0.

sassFilePath?: string

Specify the path to the Sass file that should be compiled.

script?: ScriptOptions

Configure the script domain

scriptPath?: ((path) => string)

Type declaration

    • (path): string
    • Alter the script path for complete control over where the Browsersync Javascript is served from. Whatever you return from this function will be used as the script path. Note: Requires at least version 1.5.0.

      Parameters

      • path: string

      Returns string

scrollElementMapping?: string[]

Default: [] Note: Requires at least version 2.9.0. Sync the scroll position of any element on the page - where any scrolled element will cause all others to match scroll position. This is helpful when a breakpoint alters which element is actually scrolling

scrollElements?: string[]

Sync the scroll position of any element on the page. Add any amount of CSS selectors Default: [] Note: Requires at least version 2.9.0.

scrollProportionally?: boolean

scrollProportionally: false // Sync viewports to TOP position Default: true

scrollRestoreTechnique?: string

Decide which technique should be used to restore scroll position following a reload. Can be window.name or cookie Default: 'window.name'

scrollThrottle?: number

How often to send scroll events Default: 0

serveStatic?: string[] | StaticOptions[]

Add additional directories from which static files should be served. Should only be used in proxy or snippet mode. Default: [] Note: Requires at least version 2.8.0.

serveStaticOptions?: ServeStaticOptions<ServerResponse<IncomingMessage>>

Options that are passed to the serve-static middleware when you use the string[] syntax: eg: serveStatic: ['./app']. Please see serve-static for details.

server?: string | boolean | string[] | ServerOptions

Use the built-in static server for basic HTML/JS/CSS websites. Default: false

single?: boolean

Serve an index.html file for all non-asset routes. Useful when using client-routers.

snippetOptions?: SnippetOptions

You can control how the snippet is injected onto each page via a custom regex + function. You can also provide patterns for certain urls that should be ignored from the snippet injection. Note: Requires at least version 2.0.0.

socket?: SocketOptions

Configure the Socket.IO path and namespace & domain to avoid collisions. path - Default: "/browser-sync/socket.io" clientPath - Default: "/browser-sync" namespace - Default: "/browser-sync" domain - Default: undefined port - Default: undefined clients.heartbeatTimeout - Default: 5000 Note: Requires at least version 1.6.2.

startPath?: string

The initial path to load

stats?: Stats

custom usage statistics for > 10% in my stats browsers query

supports?: boolean

should Autoprefixer add prefixes for

Supports

parameters.

tagNames?: TagNamesOptions

¯_(ツ)_/¯

timestamps?: boolean

Append timestamps to injected files Default: true

tunnel?: string | boolean

Tunnel the Browsersync server through a random Public URL Default: null

ui?: boolean | UIOptions

Browsersync includes a user-interface that is accessed via a separate port. The UI allows to controls all devices, push sync updates and much more.

port - Default: 3001 weinre.port - Default: 8080 Note: Requires at least version 2.0.0.

useFsEvents?: boolean

Whether to use the fsevents watching interface if available. When set to true explicitly and fsevents is available this supercedes the usePolling setting. When set to false on OS X, usePolling: true becomes the default.

usePolling?: boolean

Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU utilization, consider setting this to false. It is typically necessary to set this to true to successfully watch files over a network, and it may be necessary to successfully watch files in other non-standard situations. Setting to true explicitly on OS X overrides the useFsEvents default.

watch?: boolean

Watch files automatically.

watchEvents?: string[] | WatchEvents

Specify which file events to respond to. Available events: add, change, unlink, addDir, unlinkDir

watchOptions?: WatchOptions

File watching options that get passed along to Chokidar. Check their docs for available options Default: undefined Note: Requires at least version 2.6.0.

xip?: boolean

Requires an internet connection - useful for services such as Typekit as it allows you to configure domains such as *.xip.io in your kit settings Default: false

Properties - Output

charset?: boolean

If true, the compiler may prepend @charset "UTF-8"; or U+FEFF (byte-order marker) if it outputs non-ASCII CSS.

If false, the compiler never emits these byte sequences. This is ideal when concatenating or embedding in HTML <style> tags. (The output will still be UTF-8.)

Default Value

true

Compatibility

dart: "1.54.0", node: false

sourceMap?: boolean

Whether or not Sass should generate a source map. If it does, the source map will be available as CompileResult.sourceMap.

Heads up! Sass doesn't automatically add a sourceMappingURL comment to the generated CSS. It's up to callers to do that, since callers have full knowledge of where the CSS and the source map will exist in relation to one another and how they'll be served to the browser.

Default Value

false

sourceMapIncludeSources?: boolean

Whether Sass should include the sources in the generated source map.

This option has no effect if sourceMap is false.

Default Value

false

style?: OutputStyle

The OutputStyle of the compiled CSS.

Example

const source = `
h1 {
font-size: 40px;
code {
font-face: Roboto Mono;
}
}`;

let result = sass.compileString(source, {style: "expanded"});
console.log(result.css.toString());
// h1 {
// font-size: 40px;
// }
// h1 code {
// font-face: Roboto Mono;
// }

result = sass.compileString(source, {style: "compressed"})
console.log(result.css.toString());
// h1{font-size:40px}h1 code{font-face:Roboto Mono}

Properties - Plugins

functions?: Record<string, CustomFunction<"async">>

Additional built-in Sass functions that are available in all stylesheets. This option takes an object whose keys are Sass function signatures like you'd write for the @function rule and whose values are CustomFunctions.

Functions are passed JavaScript representations of Sass value types, and must return the same.

When writing custom functions, it's important to make them as user-friendly and as close to the standards set by Sass's core functions as possible. Some good guidelines to follow include:

  • Use Value.assert* methods, like Value.assertString, to cast untyped Value objects to more specific types. For values that were passed directly as arguments, pass in the argument name as well. This ensures that the user gets good error messages when they pass in the wrong type to your function.

  • Individual classes may have more specific assert* methods, like SassNumber.assertInt, which should be used when possible.

  • In Sass, every value counts as a list. Rather than trying to detect the SassList type, you should use Value.asList to treat all values as lists.

  • When manipulating values like lists, strings, and numbers that have metadata (comma versus space separated, bracketed versus unbracketed, quoted versus unquoted, units), the output metadata should match the input metadata.

  • When in doubt, lists should default to comma-separated, strings should default to quoted, and numbers should default to unitless.

  • In Sass, lists and strings use one-based indexing and use negative indices to index from the end of value. Functions should follow these conventions. Value.sassIndexToListIndex and SassString.sassIndexToStringIndex can be used to do this automatically.

  • String indexes in Sass refer to Unicode code points while JavaScript string indices refer to UTF-16 code units. For example, the character U+1F60A SMILING FACE WITH SMILING EYES is a single Unicode code point but is represented in UTF-16 as two code units (0xD83D and 0xDE0A). So in JavaScript, "a😊b".charCodeAt(1) returns 0xD83D, whereas in Sass str-slice("a😊b", 1, 1) returns "😊". Functions should follow Sass's convention. SassString.sassIndexToStringIndex can be used to do this automatically, and the SassString.sassLength getter can be used to access a string's length in code points.

Example

sass.compileString(`
h1 {
font-size: pow(2, 5) * 1px;
}`, {
functions: {
// Note: in real code, you should use `math.pow()` from the built-in
// `sass:math` module.
'pow($base, $exponent)': function(args) {
const base = args[0].assertNumber('base').assertNoUnits('base');
const exponent =
args[1].assertNumber('exponent').assertNoUnits('exponent');

return new sass.SassNumber(Math.pow(base.value, exponent.value));
}
}
});
importers?: (Importer<"async"> | FileImporter<"async">)[]

Custom importers that control how Sass resolves loads from rules like @use and @import.

Loads are resolved by trying, in order:

  • The importer that was used to load the current stylesheet, with the loaded URL resolved relative to the current stylesheet's canonical URL.

  • Each Importer or FileImporter in importers, in order.

  • Each load path in loadPaths, in order.

If none of these return a Sass file, the load fails and Sass throws an error.

Created by CodeAuthor1 Twitter