Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add api option to allow switching to sass modern compiler #166

Merged
merged 14 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
};
```

#### rollup.config.ts
### rollup.config.ts

Add `allowSyntheticDefaultImports`, or `esModuleInterop` (enables `allowSyntheticDefaultImports`), to tsconfig.json:

Expand Down Expand Up @@ -51,11 +51,12 @@ Profit.

### `output`

- Type: `Boolean|String|Function` _(default: false)_
- Type: `Boolean|String|Function`
- Default: `false`

```js
sass({
// Default behaviour disable output
// Default behavior disable output
output: false,

// Write all styles to the bundle destination where .js is replaced by .css
Expand All @@ -64,7 +65,7 @@ sass({
// Filename to write all styles
output: 'bundle.css',

// Callback that will be called ongenerate with two arguments:
// Callback that will be called on generate bundle with two arguments:
// - styles: the concatenated styles in order of imported
// - styleNodes: an array of style objects:
// [
Expand All @@ -79,7 +80,8 @@ sass({

### `insert`

- Type: `Boolean` _(default: false)_
- Type: `Boolean`
- Default: `false`

If you specify `true`, the plugin will insert compiled CSS into `<head/>` tag, via utility function that it will output
in your build bundle.
Expand Down Expand Up @@ -164,14 +166,36 @@ the exported vars.

### `runtime`

- Type: `Object` _(default: sass)_
- Type: `Object`
- Default: `sass`

If you specify an object, it will be used instead of [sass](https://github.com/sass/dart-sass). You can use this to pass a different sass compiler (for example the `node-sass` npm package).

### `api`

- Type: `'legacy'|'modern'`
- Default: `'legacy'`

```js
sass(); // default to legacy

sass({ api: 'modern' });

sass({
api: 'modern',
options: {
style: 'compressed',
},
});
```

### `options`

- Type: `Object`

> [!NOTE]
> The content of `options` is sensible to the value specified in `api` option

Options for [sass](https://github.com/sass/dart-sass) or your own runtime sass compiler.

If you specify `data`, the plugin will treat as prepend sass string.
Expand All @@ -185,6 +209,22 @@ sass({
});
```

---

> [!TIP]
> If your are working with npm packages packages, consider to use
> [NodePackageImporter](https://sass-lang.com/documentation/js-api/classes/nodepackageimporter/)
>
> ```js
> import * as sass from 'sass';
>
> sass({
> options: {
> importers: [new sass.NodePackageImporter()],
> },
> });
> ```

### `include`

- Type: `string | string[]`
Expand Down
17 changes: 12 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"build": "npm run build-downlevel-dts && tsc --project tsconfig.build.json",
"build-downlevel-dts": "node scripts/clean-and-run-downlevel-dts.js",
"downlevel-dts": "downlevel-dts . ts3.5 [--to=3.5]",
"test": "nyc --reporter=html --reporter=text ava && npm run test:rollup.config.spec.ts",
"test": "nyc --reporter=html --reporter=text ava && npm run test:types",
"test:types": "tsc --project tsconfig.spec.json --noEmit",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"output-coverage-lcov": "nyc report --reporter=text-lcov > coverage/tests.lcov",
"test:rollup.config.spec.ts": "tsc --project tsconfig.spec.json --noEmit",
"commitlint": "commitlint --edit",
"format": "prettier . --check",
"format:fix": "prettier . --write"
Expand Down
Loading