You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`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).
46
46
47
-
This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.
47
+
This allows you to control the versions of all your dependencies and to choose which Sass implementation to use.
48
48
49
49
> [!NOTE]
50
50
>
@@ -54,7 +54,7 @@ This allows you to control the versions of all your dependencies, and to choose
54
54
>
55
55
> [Node Sass](https://github.com/sass/node-sass) does not work with [Yarn PnP](https://classic.yarnpkg.com/en/docs/pnp/) and doesn't support [@use rule](https://sass-lang.com/documentation/at-rules/use).
56
56
57
-
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.
57
+
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 with the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) to extract it into a separate file.
58
58
59
59
Then add the loader to your webpack configuration. For example:
60
60
@@ -96,7 +96,7 @@ module.exports = {
96
96
};
97
97
```
98
98
99
-
Finally run `webpack` via your preferred method.
99
+
Finally run `webpack` via your preferred method (e.g., via CLI or an npm script).
100
100
101
101
### The `style` (new API, by default since 16 version) and `outputStyle` (old API) options in `production` mode
102
102
@@ -106,13 +106,14 @@ For `production` mode, the `style` (new API, by default since 16 version) and `o
106
106
107
107
Webpack provides an [advanced mechanism to resolve files](https://webpack.js.org/concepts/module-resolution/).
108
108
109
-
The `sass-loader` uses Sass's custom importer feature to pass all queries to the webpack resolving engine enabling you to import your Sass modules from `node_modules`.
109
+
The `sass-loader` uses Sass's custom importer feature to pass all queries to the webpack resolving engine, enabling you to import your Sass modules from `node_modules`.
110
110
111
111
```scss
112
112
@import"bootstrap";
113
113
```
114
114
115
115
Using `~` is deprecated and should be removed from your code, but we still support it for historical reasons.
116
+
116
117
Why can you remove it? The loader will first try to resolve `@import` as a relative path. If it cannot be resolved, then the loader will try to resolve `@import` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
117
118
118
119
Prepending module paths with a `~` tells webpack to search through [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
@@ -122,22 +123,25 @@ Prepending module paths with a `~` tells webpack to search through [`node_module
122
123
```
123
124
124
125
It's important to prepend the path with only `~`, because `~/` resolves to the home directory.
126
+
125
127
Webpack needs to distinguish between `bootstrap` and `~bootstrap` because CSS and Sass files have no special syntax for importing relative files.
128
+
126
129
Writing `@import "style.scss"` is the same as `@import "./style.scss";`
127
130
128
131
### Problems with `url(...)`
129
132
130
133
Since Sass implementations don't provide [url rewriting](https://github.com/sass/libsass/issues/532), all linked assets must be relative to the output.
131
134
132
-
- If you pass the generated CSS on to the `css-loader`, all urls must be relative to the entry-file (e.g. `main.scss`).
133
-
- If you're just generating CSS without passing it to the `css-loader`, it must be relative to your web root.
135
+
- If you pass the generated CSS on to the `css-loader`, all URLs must be relative to the entry-file (e.g. `main.scss`).
136
+
- If you're just generating CSS without passing it to the `css-loader`, URLs must be relative to your web root.
134
137
135
138
You might be surprised by this first issue, as it is natural to expect relative references to be resolved against the `.sass`/`.scss` file in which they are specified (like in regular `.css` files).
136
139
137
140
Thankfully there are two solutions to this problem:
138
141
139
-
- Add the missing url rewriting using the [resolve-url-loader](https://github.com/bholloway/resolve-url-loader). Place it before `sass-loader` in the loader chain.
140
-
- Library authors usually provide a variable to modify the asset path. [bootstrap-sass](https://github.com/twbs/bootstrap-sass) for example has an `$icon-font-path`.
142
+
- Add the missing URL rewriting using the [resolve-url-loader](https://github.com/bholloway/resolve-url-loader). Place it before `sass-loader` in the loader chain.
143
+
144
+
- Library authors usually provide a variable to modify the asset path. [bootstrap-sass](https://github.com/twbs/bootstrap-sass) for example, has an `$icon-font-path`.
141
145
142
146
## Options
143
147
@@ -164,7 +168,7 @@ The special `implementation` option determines which implementation of Sass to u
164
168
By default, the loader resolves the implementation based on your dependencies.
165
169
Just add the desired implementation to your `package.json` (`sass`, `sass-embedded`, or `node-sass` package) and install dependencies.
166
170
167
-
Example where the `sass-loader`loader uses the `sass` (`dart-sass`) implementation:
171
+
Example where the `sass-loader` uses the `sass` (`dart-sass`) implementation:
168
172
169
173
**package.json**
170
174
@@ -177,7 +181,7 @@ Example where the `sass-loader` loader uses the `sass` (`dart-sass`) implementat
177
181
}
178
182
```
179
183
180
-
Example where the `sass-loader`loader uses the `node-sass` implementation:
184
+
Example where the `sass-loader` uses the `node-sass` implementation:
181
185
182
186
**package.json**
183
187
@@ -190,7 +194,7 @@ Example where the `sass-loader` loader uses the `node-sass` implementation:
190
194
}
191
195
```
192
196
193
-
Example where the `sass-loader`loader uses the `sass-embedded` implementation:
197
+
Example where the `sass-loader` uses the `sass-embedded` implementation:
194
198
195
199
**package.json**
196
200
@@ -208,8 +212,7 @@ Example where the `sass-loader` loader uses the `sass-embedded` implementation:
208
212
209
213
> [!NOTE]
210
214
>
211
-
> Using `optionalDependencies` means that `sass-loader` can fallback to `sass`
212
-
> when running on an operating system not supported by `sass-embedded`
215
+
> Using `optionalDependencies` means that `sass-loader` can fallback to `sass` when running on an operating system not supported by `sass-embedded`
213
216
214
217
Be aware of the order that `sass-loader` will resolve the implementation:
215
218
@@ -221,7 +224,7 @@ You can specify a specific implementation by using the `implementation` option,
221
224
222
225
#### `object`
223
226
224
-
For example, to always use Dart Sass, you'd pass:
227
+
For example, to always use `Dart Sass`, you'd pass:
225
228
226
229
```js
227
230
module.exports= {
@@ -293,11 +296,11 @@ Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://g
293
296
294
297
> [!NOTE]
295
298
>
296
-
> The `charset` option is `true` by default for `dart-sass`, we strongly discourage setting this to `false`, because webpack doesn't support files other than `utf-8`.
299
+
> The `charset` option is `true` by default for `dart-sass`. We strongly discourage setting this to `false` because webpack doesn't support files other than `utf-8`.
297
300
298
301
> [!NOTE]
299
302
>
300
-
> The `syntax` (new API, by default since 16 version)`and`indentedSyntax`(old API) option is`scss`for the`scss`extension,`indented`for the`sass`extension and`css`for the`css` extension.
303
+
> The `syntax` (new API, by default since 16 version)`and`indentedSyntax`(old API) option is`scss`for the`scss`extension,`indented`for the`sass`extension and`css`for the`css` extension.
301
304
302
305
> [!NOTE]
303
306
>
@@ -398,7 +401,7 @@ type sourceMap = boolean;
398
401
399
402
Default: depends on the `compiler.devtool` value
400
403
401
-
Enables/Disables generation of source maps.
404
+
Enables/disables generation of source maps.
402
405
403
406
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
404
407
All values enable source map generation except `eval` and `false`.
@@ -434,9 +437,9 @@ module.exports = {
434
437
};
435
438
```
436
439
437
-
> ℹ In some rare cases `node-sass` can output invalid source maps (it is a `node-sass` bug).
440
+
> ℹ In some rare cases `node-sass` can output invalid source maps (this is a `node-sass` bug).
438
441
>
439
-
> 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`.
442
+
> In order to avoid this, you can try to update `node-sass` to the latest version, or you can try to set within `sassOptions` the `outputStyle` option to `compressed`.
440
443
441
444
**webpack.config.js**
442
445
@@ -586,10 +589,10 @@ type webpackImporter = boolean;
586
589
587
590
Default: `true`
588
591
589
-
Enables/Disables the default webpack importer.
592
+
Enables/disables the default webpack importer.
590
593
591
594
This can improve performance in some cases, though use it with caution because aliases and `@import` at-rules starting with `~` will not work.
592
-
You can pass your own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
595
+
You can pass your own `importer` to solve this (see [`importer` docs](https://github.com/sass/node-sass#importer--v200---experimental)).
The presented code will throw a webpack warning instead logging.
655
+
The presented code will throw a webpack warning instead of logging.
653
656
654
657
To ignore unnecessary warnings you can use the [ignoreWarnings](https://webpack.js.org/configuration/other-options/#ignorewarnings) option.
655
658
@@ -691,11 +694,11 @@ Allows you to switch between the `legacy` and `modern` APIs. You can find more i
691
694
692
695
> [!NOTE]
693
696
>
694
-
> Using `modern-compiler` and `sass-embedded` together significantly improve performance and decrease built time. We strongly recommend their use. We will enable them by default in a future major release.
697
+
> Using `modern-compiler` and `sass-embedded` together significantly improves performance and decreases build time. We strongly recommend their use. We will enable them by default in a future major release.
695
698
696
699
> [!WARNING]
697
700
>
698
-
> The sass options are different for the `legacy` and `modern` APIs. Please look at [docs](https://sass-lang.com/documentation/js-api) how to migrate to the modern options.
701
+
> The Sass options are different for the `legacy` and `modern` APIs. Please look at [docs](https://sass-lang.com/documentation/js-api) to learn how to migrate to the modern options.
699
702
700
703
**webpack.config.js**
701
704
@@ -726,7 +729,7 @@ module.exports = {
726
729
727
730
## How to enable `@debug` output
728
731
729
-
By default, the output of `@debug` messages are disabled.
732
+
By default, the output of `@debug` messages is disabled.
730
733
Add the following to **webpack.config.js** to enable them:
731
734
732
735
```js
@@ -742,7 +745,7 @@ module.exports = {
742
745
743
746
### Extracts CSS into separate files
744
747
745
-
For production builds it's recommended to extract the CSS from your bundle to be able to use parallel loading of CSS/JS resources later on.
748
+
For production builds, it's recommended to extract the CSS from your bundle to enable parallel loading of CSS/JS resources.
746
749
747
750
There are four recommended ways to extract a stylesheet from a bundle:
748
751
@@ -844,9 +847,9 @@ module.exports = {
844
847
845
848
### Source maps
846
849
847
-
Enables/Disables generation of source maps.
850
+
Enables/disables generation of source maps.
848
851
849
-
To enable CSS source maps, you'll need to pass the `sourceMap` option to the `sass-loader`_and_ the `css-loader`.
852
+
To enable CSS source maps, you'll need to pass the `sourceMap` option to both the `sass-loader`_and_ the `css-loader`.
850
853
851
854
**webpack.config.js**
852
855
@@ -878,11 +881,13 @@ module.exports = {
878
881
};
879
882
```
880
883
881
-
If you want to edit the original Sass files inside Chrome, [there's a good blog post](https://medium.com/@toolmantim/getting-started-with-css-sourcemaps-and-in-browser-sass-editing-b4daab987fb0). Checkout [test/sourceMap](https://github.com/webpack-contrib/sass-loader/tree/master/test) for a running example.
884
+
If you want to edit the original Sass files inside Chrome, [there's a good blog post](https://medium.com/@toolmantim/getting-started-with-css-sourcemaps-and-in-browser-sass-editing-b4daab987fb0).
885
+
Checkout [test/sourceMap](https://github.com/webpack-contrib/sass-loader/tree/master/test) for a working example.
882
886
883
887
## Contributing
884
888
885
-
Please take a moment to read our contributing guidelines if you haven't yet done so.
889
+
We welcome all contributions!
890
+
If you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.
0 commit comments