Skip to content

Commit 24c852a

Browse files
docs: options table (#834)
1 parent f892eba commit 24c852a

File tree

1 file changed

+55
-44
lines changed

1 file changed

+55
-44
lines changed

README.md

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,17 @@ Thankfully there are a two solutions to this problem:
104104

105105
## Options
106106

107+
| Name | Type | Default | Description |
108+
| :---------------------------------------: | :------------------: | :-------------------------------------: | :-------------------------------------------------------- |
109+
| **[`implementation`](#implementation)** | `{Object}` | `sass` | Setup Sass implementation to use. |
110+
| **[`sassOptions`](#sassoptions)** | `{Object\|Function}` | defaults values for Sass implementation | Options for Sass. |
111+
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps. |
112+
| **[`prependData`](#sassoptions)** | `{String\|Function}` | `undefined` | Prepends `Sass`/`SCSS` code before the actual entry file. |
113+
| **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. |
114+
107115
### `implementation`
108116

117+
Type: `Object`
109118
Default: `sass`
110119

111120
The special `implementation` option determines which implementation of Sass to use.
@@ -247,6 +256,7 @@ module.exports = {
247256
### `sassOptions`
248257

249258
Type: `Object|Function`
259+
Default: defaults values for Sass implementation
250260

251261
Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://github.com/sass/node-sass) implementation.
252262

@@ -334,19 +344,19 @@ module.exports = {
334344
};
335345
```
336346

337-
### `prependData`
347+
### `sourceMap`
338348

339-
Type: `String|Function`
340-
Default: `undefined`
349+
Type: `Boolean`
350+
Default: depends on the `compiler.devtool` value
341351

342-
Prepends `Sass`/`SCSS` code before the actual entry file.
343-
In this case, the `sass-loader` will not override the `data` option but just append the entry's content.
352+
Enables/Disables generation of source maps.
344353

345-
This is especially useful when some of your Sass variables depend on the environment:
354+
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
355+
All values enable source map generation except `eval` and `false` value.
346356

347-
> Since you're injecting code, this will break the source mappings in your entry file. Often there's a simpler solution than this, like multiple Sass entry files.
357+
> If a `true` the `sourceMap`, `sourceMapRoot`, `sourceMapEmbed`, `sourceMapContents` and `omitSourceMapUrl` from `sassOptions` will be ignored.
348358
349-
#### `String`
359+
**webpack.config.js**
350360

351361
```js
352362
module.exports = {
@@ -356,11 +366,16 @@ module.exports = {
356366
test: /\.s[ac]ss$/i,
357367
use: [
358368
'style-loader',
359-
'css-loader',
369+
{
370+
loader: 'css-loader',
371+
options: {
372+
sourceMap: true,
373+
},
374+
},
360375
{
361376
loader: 'sass-loader',
362377
options: {
363-
prependData: '$env: ' + process.env.NODE_ENV + ';',
378+
sourceMap: true,
364379
},
365380
},
366381
],
@@ -370,7 +385,10 @@ module.exports = {
370385
};
371386
```
372387

373-
#### `Function`
388+
> ℹ In some rare cases `node-sass` can output invalid source maps (it is a `node-sass` bug).
389+
> In order to avoid this, you can try to update `node-sass` to latest version or you can try to set within `sassOptions` the `outputStyle` option to `compressed`.
390+
391+
**webpack.config.js**
374392

375393
```js
376394
module.exports = {
@@ -384,16 +402,9 @@ module.exports = {
384402
{
385403
loader: 'sass-loader',
386404
options: {
387-
prependData: (loaderContext) => {
388-
// More information about available properties https://webpack.js.org/api/loaders/
389-
const { resourcePath, rootContext } = loaderContext;
390-
const relativePath = path.relative(rootContext, resourcePath);
391-
392-
if (relativePath === 'styles/foo.scss') {
393-
return '$value: 100px;';
394-
}
395-
396-
return '$value: 200px;';
405+
sourceMap: true,
406+
sassOptions: {
407+
outputStyle: 'compressed',
397408
},
398409
},
399410
},
@@ -404,19 +415,19 @@ module.exports = {
404415
};
405416
```
406417

407-
### `sourceMap`
418+
### `prependData`
408419

409-
Type: `Boolean`
410-
Default: depends on the `compiler.devtool` value
420+
Type: `String|Function`
421+
Default: `undefined`
411422

412-
Enables/Disables generation of source maps.
423+
Prepends `Sass`/`SCSS` code before the actual entry file.
424+
In this case, the `sass-loader` will not override the `data` option but just append the entry's content.
413425

414-
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
415-
All values enable source map generation except `eval` and `false` value.
426+
This is especially useful when some of your Sass variables depend on the environment:
416427

417-
> If a `true` the `sourceMap`, `sourceMapRoot`, `sourceMapEmbed`, `sourceMapContents` and `omitSourceMapUrl` from `sassOptions` will be ignored.
428+
> Since you're injecting code, this will break the source mappings in your entry file. Often there's a simpler solution than this, like multiple Sass entry files.
418429
419-
**webpack.config.js**
430+
#### `String`
420431

421432
```js
422433
module.exports = {
@@ -426,16 +437,11 @@ module.exports = {
426437
test: /\.s[ac]ss$/i,
427438
use: [
428439
'style-loader',
429-
{
430-
loader: 'css-loader',
431-
options: {
432-
sourceMap: true,
433-
},
434-
},
440+
'css-loader',
435441
{
436442
loader: 'sass-loader',
437443
options: {
438-
sourceMap: true,
444+
prependData: '$env: ' + process.env.NODE_ENV + ';',
439445
},
440446
},
441447
],
@@ -445,10 +451,7 @@ module.exports = {
445451
};
446452
```
447453

448-
> ℹ In some rare cases `node-sass` can output invalid source maps (it is a `node-sass` bug).
449-
> In order to avoid this, you can try to update `node-sass` to latest version or you can try to set within `sassOptions` the `outputStyle` option to `compressed`.
450-
451-
**webpack.config.js**
454+
#### `Function`
452455

453456
```js
454457
module.exports = {
@@ -462,9 +465,16 @@ module.exports = {
462465
{
463466
loader: 'sass-loader',
464467
options: {
465-
sourceMap: true,
466-
sassOptions: {
467-
outputStyle: 'compressed',
468+
prependData: (loaderContext) => {
469+
// More information about available properties https://webpack.js.org/api/loaders/
470+
const { resourcePath, rootContext } = loaderContext;
471+
const relativePath = path.relative(rootContext, resourcePath);
472+
473+
if (relativePath === 'styles/foo.scss') {
474+
return '$value: 100px;';
475+
}
476+
477+
return '$value: 200px;';
468478
},
469479
},
470480
},
@@ -482,7 +492,8 @@ Default: `true`
482492

483493
Enables/Disables the default Webpack importer.
484494

485-
This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starting with `~` will not work. You can pass own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
495+
This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starting with `~` will not work.
496+
You can pass own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
486497

487498
**webpack.config.js**
488499

0 commit comments

Comments
 (0)