Skip to content

Commit

Permalink
feat: added sass-embedded support and the api option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 14, 2022
1 parent ff8d078 commit afbe114
Show file tree
Hide file tree
Showing 30 changed files with 388,635 additions and 190,548 deletions.
47 changes: 46 additions & 1 deletion README.md
Expand Up @@ -39,14 +39,16 @@ or
pnpm add -D sass-loader sass webpack
```

`sass-loader` requires you to install either [Dart Sass](https://github.com/sass/dart-sass) or [Node Sass](https://github.com/sass/node-sass) on your own (more documentation can be found below).
`sass-loader` requires you to install either [Dart Sass](https://github.com/sass/dart-sass), [Node Sass](https://github.com/sass/node-sass) on your own (more documentation can be found below) or [Sass Embedded](https://github.com/sass/embedded-host-node).

This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.

> ℹ️ We highly recommend using [Dart Sass](https://github.com/sass/dart-sass).
> [Node Sass](https://github.com/sass/node-sass) does not work with [Yarn PnP](https://classic.yarnpkg.com/en/docs/pnp/) feature and doesn't support [@use rule](https://sass-lang.com/documentation/at-rules/use).
> [Sass Embedded](https://github.com/sass/embedded-host-node) is experimental and in `beta`, therefore some features may not work
Chain the `sass-loader` with the [css-loader](https://github.com/webpack-contrib/css-loader) and the [style-loader](https://github.com/webpack-contrib/style-loader) to immediately apply all styles to the DOM or the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) to extract it into a separate file.

Then add the loader to your Webpack configuration. For example:
Expand Down Expand Up @@ -712,6 +714,49 @@ module.exports = {
};
```

### `api`

Type:

```ts
type api = "legacy" | "modern";
```

Default: `"legacy"`

Allows you to switch between `legacy` and `modern` API. You can find more information [here](https://sass-lang.com/documentation/js-api).

> ⚠ "modern" API is experimental, so some features may not work (known: built-in `importer` is not working and files with errors is not watching on initial run), you can follow this [here](https://github.com/webpack-contrib/sass-loader/issues/774).
> ⚠ The sass options are different for `modern` and `old` APIs. Please look at [docs](https://sass-lang.com/documentation/js-api) how to migrate on new options.
**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
"style-loader",
"css-loader",
{
loader: "sass-loader",
options: {
api: "modern",
sassOptions: {
// Your sass options
},
},
},
],
},
],
},
};
```

## Examples

### Extracts CSS into separate files
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
@@ -1,3 +1,3 @@
module.exports = {
testEnvironment: "node",
testEnvironment: "jest-environment-node-single-context",
};

0 comments on commit afbe114

Please sign in to comment.