sass-loader 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -1
- package/LICENSE +16 -14
- package/README.md +486 -192
- package/dist/SassError.js +33 -0
- package/dist/cjs.js +5 -0
- package/dist/getDefaultSassImplementation.js +28 -0
- package/dist/getRenderFunctionFromSassImplementation.js +39 -0
- package/dist/getSassImplementation.js +56 -0
- package/dist/getSassOptions.js +116 -0
- package/dist/importsToResolve.js +88 -0
- package/dist/index.js +114 -0
- package/dist/options.json +41 -0
- package/{lib → dist}/proxyCustomImporters.js +14 -12
- package/dist/webpackImporter.js +75 -0
- package/package.json +88 -54
- package/lib/formatSassError.js +0 -73
- package/lib/importsToResolve.js +0 -60
- package/lib/loader.js +0 -124
- package/lib/normalizeOptions.js +0 -78
- package/lib/webpackImporter.js +0 -72
package/README.md
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
[![npm][npm]][npm-url]
|
|
2
|
-
[![node][node]][node-url]
|
|
3
|
-
[![npm-stats][npm-stats]][npm-url]
|
|
4
|
-
[![deps][deps]][deps-url]
|
|
5
|
-
[![travis][travis]][travis-url]
|
|
6
|
-
[![appveyor][appveyor]][appveyor-url]
|
|
7
|
-
[![coverage][cover]][cover-url]
|
|
8
|
-
[![chat][chat]][chat-url]
|
|
9
|
-
|
|
10
1
|
<div align="center">
|
|
11
2
|
<img height="100"
|
|
12
3
|
src="https://worldvectorlogo.com/logos/sass-1.svg">
|
|
@@ -14,276 +5,579 @@
|
|
|
14
5
|
<img width="200" height="200"
|
|
15
6
|
src="https://webpack.js.org/assets/icon-square-big.svg">
|
|
16
7
|
</a>
|
|
17
|
-
<h1>Sass Loader</h1>
|
|
18
|
-
<p>Loads a Sass/SCSS file and compiles it to CSS.</p>
|
|
19
8
|
</div>
|
|
20
9
|
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
[![npm][npm]][npm-url]
|
|
11
|
+
[![node][node]][node-url]
|
|
12
|
+
[![deps][deps]][deps-url]
|
|
13
|
+
[![tests][tests]][tests-url]
|
|
14
|
+
[![coverage][cover]][cover-url]
|
|
15
|
+
[![chat][chat]][chat-url]
|
|
16
|
+
[![size][size]][size-url]
|
|
17
|
+
|
|
18
|
+
# sass-loader
|
|
19
|
+
|
|
20
|
+
Loads a Sass/SCSS file and compiles it to CSS.
|
|
21
|
+
|
|
22
|
+
## Getting Started
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
To begin, you'll need to install `sass-loader`:
|
|
25
25
|
|
|
26
|
-
```
|
|
26
|
+
```console
|
|
27
27
|
npm install sass-loader node-sass webpack --save-dev
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
The sass-loader requires [
|
|
31
|
-
|
|
32
|
-
and it requires you to install either [Node Sass][] or [Dart Sass][] on your
|
|
33
|
-
own. This allows you to control the versions of all your dependencies, and to
|
|
34
|
-
choose which Sass implementation to use.
|
|
30
|
+
The sass-loader requires you to install either [Node Sass](https://github.com/sass/node-sass) or [Dart Sass](https://github.com/sass/dart-sass) on your own (more documentation you can find below).
|
|
31
|
+
This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.
|
|
35
32
|
|
|
36
|
-
[
|
|
37
|
-
[
|
|
33
|
+
- [node sass](https://github.com/sass/node-sass)
|
|
34
|
+
- [dart sass](http://sass-lang.com/dart-sass)
|
|
38
35
|
|
|
39
|
-
|
|
36
|
+
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.
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
Then add the loader to your `webpack` config. For example:
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
**file.js**
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import style from './style.scss';
|
|
45
44
|
```
|
|
46
45
|
|
|
46
|
+
**file.scss**
|
|
47
|
+
|
|
48
|
+
```scss
|
|
49
|
+
$body-color: red;
|
|
50
|
+
|
|
51
|
+
body {
|
|
52
|
+
color: $body-color;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**webpack.config.js**
|
|
57
|
+
|
|
47
58
|
```js
|
|
48
|
-
// webpack.config.js
|
|
49
59
|
module.exports = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
module: {
|
|
61
|
+
rules: [
|
|
62
|
+
{
|
|
63
|
+
test: /\.s[ac]ss$/i,
|
|
64
|
+
use: [
|
|
65
|
+
// Creates `style` nodes from JS strings
|
|
66
|
+
'style-loader',
|
|
67
|
+
// Translates CSS into CommonJS
|
|
68
|
+
'css-loader',
|
|
69
|
+
// Compiles Sass to CSS
|
|
70
|
+
'sass-loader',
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
61
75
|
};
|
|
62
76
|
```
|
|
63
77
|
|
|
64
|
-
|
|
78
|
+
And run `webpack` via your preferred method.
|
|
79
|
+
|
|
80
|
+
### Resolving `import` at-rules
|
|
81
|
+
|
|
82
|
+
The webpack provides an [advanced mechanism to resolve files](https://webpack.js.org/concepts/module-resolution/).
|
|
83
|
+
|
|
84
|
+
The sass-loader uses Sass's custom importer feature to pass all queries to the webpack resolving engine. Thus you can import your Sass modules from `node_modules`. Just prepend them with a `~` to tell webpack that this is not a relative import:
|
|
85
|
+
|
|
86
|
+
```css
|
|
87
|
+
@import '~bootstrap';
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
It's important to only prepend it with `~`, because `~/` resolves to the home directory.
|
|
91
|
+
The webpack needs to distinguish between `bootstrap` and `~bootstrap` because CSS and Sass files have no special syntax for importing relative files.
|
|
92
|
+
Writing `@import "file"` is the same as `@import "./file";`
|
|
93
|
+
|
|
94
|
+
### Problems with `url(...)`
|
|
95
|
+
|
|
96
|
+
Since sass implementations don't provide [url rewriting](https://github.com/sass/libsass/issues/532), all linked assets must be relative to the output.
|
|
97
|
+
|
|
98
|
+
- If you pass the generated CSS on to the css-loader, all urls must be relative to the entry-file (e.g. `main.scss`).
|
|
99
|
+
- If you're just generating CSS without passing it to the css-loader, it must be relative to your web root.
|
|
100
|
+
|
|
101
|
+
You will be disrupted by this first issue. 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).
|
|
102
|
+
|
|
103
|
+
Thankfully there are a two solutions to this problem:
|
|
104
|
+
|
|
105
|
+
- Add the missing url rewriting using the [resolve-url-loader](https://github.com/bholloway/resolve-url-loader). Place it before the sass-loader in the loader chain.
|
|
106
|
+
- 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`.
|
|
107
|
+
|
|
108
|
+
## Options
|
|
109
|
+
|
|
110
|
+
### `implementation`
|
|
111
|
+
|
|
112
|
+
The special `implementation` option determines which implementation of Sass to use.
|
|
113
|
+
|
|
114
|
+
By default the loader resolve the implementation based on your dependencies.
|
|
115
|
+
Just add required implementation to `package.json` (`node-sass` or `sass` package) and install dependencies.
|
|
116
|
+
|
|
117
|
+
Example where the `sass-loader` loader uses the `sass` (`dart-sass`) implementation:
|
|
118
|
+
|
|
119
|
+
**package.json**
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"devDependencies": {
|
|
124
|
+
"sass-loader": "^7.2.0",
|
|
125
|
+
"sass": "^1.22.10"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Example where the `sass-loader` loader uses the `node-sass` implementation:
|
|
131
|
+
|
|
132
|
+
**package.json**
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"devDependencies": {
|
|
137
|
+
"sass-loader": "^7.2.0",
|
|
138
|
+
"node-sass": "^4.0.0"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Beware the situation when `node-sass` and `sass` was installed, by default the `sass-loader` prefers `node-sass`, to avoid this situation use the `implementation` option.
|
|
144
|
+
|
|
145
|
+
It takes either `node-sass` or `sass` (`Dart Sass`) module.
|
|
146
|
+
|
|
147
|
+
For example, to use Dart Sass, you'd pass:
|
|
65
148
|
|
|
66
149
|
```js
|
|
67
|
-
// webpack.config.js
|
|
68
150
|
module.exports = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
151
|
+
module: {
|
|
152
|
+
rules: [
|
|
153
|
+
{
|
|
154
|
+
test: /\.s[ac]ss$/i,
|
|
155
|
+
use: [
|
|
156
|
+
'style-loader',
|
|
157
|
+
'css-loader',
|
|
158
|
+
{
|
|
159
|
+
loader: 'sass-loader',
|
|
160
|
+
options: {
|
|
161
|
+
// Prefer `dart-sass`
|
|
162
|
+
implementation: require('sass'),
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Note that when using `sass` (`Dart Sass`), **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks.
|
|
173
|
+
To avoid this overhead, you can use the [fibers](https://www.npmjs.com/package/fibers) package to call asynchronous importers from the synchronous code path.
|
|
174
|
+
|
|
175
|
+
We automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package (setup `sassOptions.fiber`) if is possible (i.e. you need install the [`fibers`](https://github.com/laverdet/node-fibers) package).
|
|
176
|
+
|
|
177
|
+
**package.json**
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"devDependencies": {
|
|
182
|
+
"sass-loader": "^7.2.0",
|
|
183
|
+
"sass": "^1.22.10",
|
|
184
|
+
"fibers": "^4.0.1"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
You can disable automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package pass the `false` value for the `sassOptions.fiber` option.
|
|
190
|
+
|
|
191
|
+
**webpack.config.js**
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
module.exports = {
|
|
195
|
+
module: {
|
|
196
|
+
rules: [
|
|
197
|
+
{
|
|
198
|
+
test: /\.s[ac]ss$/i,
|
|
199
|
+
use: [
|
|
200
|
+
'style-loader',
|
|
201
|
+
'css-loader',
|
|
202
|
+
{
|
|
203
|
+
loader: 'sass-loader',
|
|
204
|
+
options: {
|
|
205
|
+
implementation: require('sass'),
|
|
206
|
+
sassOptions: {
|
|
207
|
+
fiber: false,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
},
|
|
85
215
|
};
|
|
86
216
|
```
|
|
87
217
|
|
|
88
|
-
|
|
218
|
+
Also you can pass own the `fiber` value using this code:
|
|
89
219
|
|
|
90
|
-
|
|
91
|
-
use. It takes either a [Node Sass][] or a [Dart Sass][] module. For example, to
|
|
92
|
-
use Dart Sass, you'd pass:
|
|
220
|
+
**webpack.config.js**
|
|
93
221
|
|
|
94
222
|
```js
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
223
|
+
module.exports = {
|
|
224
|
+
module: {
|
|
225
|
+
rules: [
|
|
226
|
+
{
|
|
227
|
+
test: /\.s[ac]ss$/i,
|
|
228
|
+
use: [
|
|
229
|
+
'style-loader',
|
|
230
|
+
'css-loader',
|
|
231
|
+
{
|
|
232
|
+
loader: 'sass-loader',
|
|
233
|
+
options: {
|
|
234
|
+
implementation: require('sass'),
|
|
235
|
+
sassOptions: {
|
|
236
|
+
fiber: require('fibers'),
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
};
|
|
103
245
|
```
|
|
104
246
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
247
|
+
### `sassOptions`
|
|
248
|
+
|
|
249
|
+
Type: `Object|Function`
|
|
250
|
+
|
|
251
|
+
Options for [Node Sass](https://github.com/sass/node-sass) or [Dart Sass](http://sass-lang.com/dart-sass) implementation.
|
|
252
|
+
|
|
253
|
+
> ℹ️ The `indentedSyntax` option has `true` value for the `sass` extension.
|
|
254
|
+
|
|
255
|
+
> ℹ️ Options such as `file` and `outFile` are unavailable.
|
|
256
|
+
|
|
257
|
+
> ℹ We recommend don't use `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because loader automatically setup this options.
|
|
258
|
+
|
|
259
|
+
There is a slight difference between the `node-sass` and `sass` (`Dart Sass`) options.
|
|
260
|
+
We recommend look documentation before used them:
|
|
261
|
+
|
|
262
|
+
- [the Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
|
|
263
|
+
- [the Dart Sass documentation](https://github.com/sass/dart-sass#javascript-api) for all available `sass` options.
|
|
264
|
+
|
|
265
|
+
#### `Object`
|
|
266
|
+
|
|
267
|
+
Setups option as object for sass implementation.
|
|
268
|
+
|
|
269
|
+
**webpack.config.js**
|
|
111
270
|
|
|
112
271
|
```js
|
|
113
|
-
|
|
114
|
-
|
|
272
|
+
module.exports = {
|
|
273
|
+
module: {
|
|
274
|
+
rules: [
|
|
275
|
+
{
|
|
276
|
+
test: /\.s[ac]ss$/i,
|
|
277
|
+
use: [
|
|
278
|
+
'style-loader',
|
|
279
|
+
'css-loader',
|
|
280
|
+
{
|
|
281
|
+
loader: 'sass-loader',
|
|
282
|
+
options: {
|
|
283
|
+
sassOptions: {
|
|
284
|
+
indentWidth: 4,
|
|
285
|
+
includePaths: ['absolute/path/a', 'absolute/path/b'],
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
#### `Function`
|
|
297
|
+
|
|
298
|
+
Allows setup difference options based on loader context.
|
|
115
299
|
|
|
300
|
+
```js
|
|
116
301
|
module.exports = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
302
|
+
module: {
|
|
303
|
+
rules: [
|
|
304
|
+
{
|
|
305
|
+
test: /\.s[ac]ss$/i,
|
|
306
|
+
use: [
|
|
307
|
+
'style-loader',
|
|
308
|
+
'css-loader',
|
|
309
|
+
{
|
|
310
|
+
loader: 'sass-loader',
|
|
311
|
+
options: {
|
|
312
|
+
sassOptions: (loaderContext) => {
|
|
313
|
+
// More information about available properties https://webpack.js.org/api/loaders/
|
|
314
|
+
const { resourcePath, rootContext } = loaderContext;
|
|
315
|
+
const relativePath = path.relative(rootContext, resourcePath);
|
|
316
|
+
|
|
317
|
+
if (relativePath === 'styles/foo.scss') {
|
|
318
|
+
return {
|
|
319
|
+
includePaths: ['absolute/path/c', 'absolute/path/d'],
|
|
320
|
+
};
|
|
130
321
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
includePaths: ['absolute/path/a', 'absolute/path/b'],
|
|
325
|
+
};
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
},
|
|
134
333
|
};
|
|
135
334
|
```
|
|
136
335
|
|
|
137
|
-
###
|
|
336
|
+
### `prependData`
|
|
337
|
+
|
|
338
|
+
Type: `String|Function`
|
|
339
|
+
Default: `undefined`
|
|
340
|
+
|
|
341
|
+
Prepends `Sass`/`SCSS` code before the actual entry file.
|
|
342
|
+
In this case, the `sass-loader` will not override the `data` option but just append the entry's content.
|
|
343
|
+
|
|
344
|
+
This is especially useful when some of your Sass variables depend on the environment:
|
|
345
|
+
|
|
346
|
+
> ℹ 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.
|
|
138
347
|
|
|
139
|
-
|
|
348
|
+
#### `String`
|
|
140
349
|
|
|
141
350
|
```js
|
|
142
|
-
|
|
351
|
+
module.exports = {
|
|
352
|
+
module: {
|
|
353
|
+
rules: [
|
|
354
|
+
{
|
|
355
|
+
test: /\.s[ac]ss$/i,
|
|
356
|
+
use: [
|
|
357
|
+
'style-loader',
|
|
358
|
+
'css-loader',
|
|
359
|
+
{
|
|
360
|
+
loader: 'sass-loader',
|
|
361
|
+
options: {
|
|
362
|
+
prependData: '$env: ' + process.env.NODE_ENV + ';',
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
#### `Function`
|
|
143
373
|
|
|
374
|
+
```js
|
|
144
375
|
module.exports = {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
376
|
+
module: {
|
|
377
|
+
rules: [
|
|
378
|
+
{
|
|
379
|
+
test: /\.s[ac]ss$/i,
|
|
380
|
+
use: [
|
|
381
|
+
'style-loader',
|
|
382
|
+
'css-loader',
|
|
383
|
+
{
|
|
384
|
+
loader: 'sass-loader',
|
|
385
|
+
options: {
|
|
386
|
+
prependData: (loaderContext) => {
|
|
387
|
+
// More information about available properties https://webpack.js.org/api/loaders/
|
|
388
|
+
const { resourcePath, rootContext } = loaderContext;
|
|
389
|
+
const relativePath = path.relative(rootContext, resourcePath);
|
|
390
|
+
|
|
391
|
+
if (relativePath === 'styles/foo.scss') {
|
|
392
|
+
return '$value: 100px;';
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return '$value: 200px;';
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
],
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
},
|
|
165
403
|
};
|
|
166
404
|
```
|
|
167
405
|
|
|
168
|
-
|
|
406
|
+
### `sourceMap`
|
|
169
407
|
|
|
170
|
-
|
|
408
|
+
Type: `Boolean`
|
|
409
|
+
Default: depends on the `compiler.devtool` value
|
|
171
410
|
|
|
172
|
-
|
|
411
|
+
Enables/Disables generation of source maps.
|
|
173
412
|
|
|
174
|
-
|
|
175
|
-
|
|
413
|
+
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option, all values enable source map generation except `eval` and `false` value.
|
|
414
|
+
|
|
415
|
+
**webpack.config.js**
|
|
416
|
+
|
|
417
|
+
```js
|
|
418
|
+
module.exports = {
|
|
419
|
+
module: {
|
|
420
|
+
rules: [
|
|
421
|
+
{
|
|
422
|
+
test: /\.s[ac]ss$/i,
|
|
423
|
+
use: [
|
|
424
|
+
'style-loader',
|
|
425
|
+
{
|
|
426
|
+
loader: 'css-loader',
|
|
427
|
+
options: {
|
|
428
|
+
sourceMap: true,
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
loader: 'sass-loader',
|
|
433
|
+
options: {
|
|
434
|
+
sourceMap: true,
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
],
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
},
|
|
441
|
+
};
|
|
176
442
|
```
|
|
177
443
|
|
|
178
|
-
|
|
444
|
+
> ℹ In some rare case `node-sass` can output invalid source maps (it is `node-sass` bug), to avoid try to update node-sass to latest version or you can try to set the `outputStyle` option to `compressed` value.
|
|
179
445
|
|
|
180
|
-
###
|
|
446
|
+
### `webpackImporter`
|
|
181
447
|
|
|
182
|
-
|
|
448
|
+
Type: `Boolean`
|
|
449
|
+
Default: `true`
|
|
183
450
|
|
|
184
|
-
|
|
185
|
-
- If you pass the generated CSS on to the css-loader, all urls must be relative to the entry-file (e.g. `main.scss`).
|
|
451
|
+
Enables/Disables default `webpack` importer.
|
|
186
452
|
|
|
187
|
-
|
|
453
|
+
This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starts with `~` will not work, but you can pass own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
|
|
188
454
|
|
|
189
|
-
|
|
190
|
-
- 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`. Check out [this working bootstrap example](https://github.com/webpack-contrib/sass-loader/tree/master/test/bootstrapSass).
|
|
455
|
+
**webpack.config.js**
|
|
191
456
|
|
|
192
|
-
|
|
457
|
+
```js
|
|
458
|
+
module.exports = {
|
|
459
|
+
module: {
|
|
460
|
+
rules: [
|
|
461
|
+
{
|
|
462
|
+
test: /\.s[ac]ss$/i,
|
|
463
|
+
use: [
|
|
464
|
+
'style-loader',
|
|
465
|
+
'css-loader',
|
|
466
|
+
{
|
|
467
|
+
loader: 'sass-loader',
|
|
468
|
+
options: {
|
|
469
|
+
webpackImporter: false,
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
},
|
|
474
|
+
],
|
|
475
|
+
},
|
|
476
|
+
};
|
|
477
|
+
```
|
|
193
478
|
|
|
194
|
-
|
|
479
|
+
## Examples
|
|
480
|
+
|
|
481
|
+
### Extracts CSS into separate files
|
|
482
|
+
|
|
483
|
+
For production builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.
|
|
195
484
|
|
|
196
485
|
There are two possibilities to extract a style sheet from the bundle:
|
|
197
486
|
|
|
487
|
+
- [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) (use this, when using webpack 4 configuration. Works in all use-cases)
|
|
198
488
|
- [extract-loader](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
|
|
199
|
-
- [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) (more complex, but works in all use-cases)
|
|
200
489
|
|
|
201
|
-
|
|
490
|
+
**webpack.config.js**
|
|
202
491
|
|
|
203
|
-
|
|
492
|
+
```js
|
|
493
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
204
494
|
|
|
205
|
-
```javascript
|
|
206
495
|
module.exports = {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
496
|
+
module: {
|
|
497
|
+
rules: [
|
|
498
|
+
{
|
|
499
|
+
test: /\.s[ac]ss$/i,
|
|
500
|
+
use: [
|
|
501
|
+
// fallback to style-loader in development
|
|
502
|
+
process.env.NODE_ENV !== 'production'
|
|
503
|
+
? 'style-loader'
|
|
504
|
+
: MiniCssExtractPlugin.loader,
|
|
505
|
+
'css-loader',
|
|
506
|
+
'sass-loader',
|
|
507
|
+
],
|
|
508
|
+
},
|
|
509
|
+
],
|
|
510
|
+
},
|
|
511
|
+
plugins: [
|
|
512
|
+
new MiniCssExtractPlugin({
|
|
513
|
+
// Options similar to the same options in webpackOptions.output
|
|
514
|
+
// both options are optional
|
|
515
|
+
filename: '[name].css',
|
|
516
|
+
chunkFilename: '[id].css',
|
|
517
|
+
}),
|
|
518
|
+
],
|
|
225
519
|
};
|
|
226
520
|
```
|
|
227
521
|
|
|
228
|
-
|
|
522
|
+
### Source maps
|
|
229
523
|
|
|
230
|
-
|
|
524
|
+
Enables/Disables generation of source maps.
|
|
231
525
|
|
|
232
|
-
|
|
526
|
+
To enable CSS source maps, you'll need to pass the `sourceMap` option to the sass-loader _and_ the css-loader.
|
|
527
|
+
|
|
528
|
+
**webpack.config.js**
|
|
233
529
|
|
|
234
530
|
```javascript
|
|
235
|
-
{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
531
|
+
module.exports = {
|
|
532
|
+
devtool: 'source-map', // any "source-map"-like devtool is possible
|
|
533
|
+
module: {
|
|
534
|
+
rules: [
|
|
535
|
+
{
|
|
536
|
+
test: /\.scss$/,
|
|
537
|
+
use: [
|
|
538
|
+
'style-loader',
|
|
539
|
+
{
|
|
540
|
+
loader: 'css-loader',
|
|
541
|
+
options: {
|
|
542
|
+
sourceMap: true,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
loader: 'sass-loader',
|
|
547
|
+
options: {
|
|
548
|
+
sourceMap: true,
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
],
|
|
552
|
+
},
|
|
553
|
+
],
|
|
554
|
+
},
|
|
555
|
+
};
|
|
241
556
|
```
|
|
242
557
|
|
|
243
|
-
|
|
558
|
+
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.
|
|
244
559
|
|
|
245
|
-
|
|
560
|
+
## Contributing
|
|
246
561
|
|
|
247
|
-
|
|
248
|
-
<tr>
|
|
249
|
-
<td align="center">
|
|
250
|
-
<a href="https://github.com/jhnns"><img width="150" height="150" src="https://avatars0.githubusercontent.com/u/781746?v=3"></a><br>
|
|
251
|
-
<a href="https://github.com/jhnns">Johannes Ewald</a>
|
|
252
|
-
</td>
|
|
253
|
-
<td align="center">
|
|
254
|
-
<a href="https://github.com/webpack-contrib"><img width="150" height="150" src="https://avatars1.githubusercontent.com/u/1243901?v=3&s=460"></a><br>
|
|
255
|
-
<a href="https://github.com/webpack-contrib">Jorik Tangelder</a>
|
|
256
|
-
</td>
|
|
257
|
-
<td align="center">
|
|
258
|
-
<a href="https://github.com/akiran"><img width="150" height="150" src="https://avatars1.githubusercontent.com/u/3403295?v=3"></a><br>
|
|
259
|
-
<a href="https://github.com/akiran">Kiran</a>
|
|
260
|
-
</td>
|
|
261
|
-
<tr>
|
|
262
|
-
</table>
|
|
562
|
+
Please take a moment to read our contributing guidelines if you haven't yet done so.
|
|
263
563
|
|
|
564
|
+
[CONTRIBUTING](./.github/CONTRIBUTING.md)
|
|
264
565
|
|
|
265
|
-
|
|
566
|
+
## License
|
|
266
567
|
|
|
267
|
-
[MIT](
|
|
568
|
+
[MIT](./LICENSE)
|
|
268
569
|
|
|
269
570
|
[npm]: https://img.shields.io/npm/v/sass-loader.svg
|
|
270
|
-
[npm-stats]: https://img.shields.io/npm/dm/sass-loader.svg
|
|
271
571
|
[npm-url]: https://npmjs.com/package/sass-loader
|
|
272
|
-
|
|
273
572
|
[node]: https://img.shields.io/node/v/sass-loader.svg
|
|
274
573
|
[node-url]: https://nodejs.org
|
|
275
|
-
|
|
276
574
|
[deps]: https://david-dm.org/webpack-contrib/sass-loader.svg
|
|
277
575
|
[deps-url]: https://david-dm.org/webpack-contrib/sass-loader
|
|
278
|
-
|
|
279
|
-
[
|
|
280
|
-
[travis-url]: https://travis-ci.org/webpack-contrib/sass-loader
|
|
281
|
-
|
|
282
|
-
[appveyor-url]: https://ci.appveyor.com/project/webpack-contrib/sass-loader/branch/master
|
|
283
|
-
[appveyor]: https://ci.appveyor.com/api/projects/status/rqpy1vaovh20ttxs/branch/master?svg=true
|
|
284
|
-
|
|
576
|
+
[tests]: https://dev.azure.com/webpack-contrib/sass-loader/_apis/build/status/webpack-contrib.sass-loader?branchName=master
|
|
577
|
+
[tests-url]: https://dev.azure.com/webpack-contrib/sass-loader/_build/latest?definitionId=21&branchName=master
|
|
285
578
|
[cover]: https://codecov.io/gh/webpack-contrib/sass-loader/branch/master/graph/badge.svg
|
|
286
579
|
[cover-url]: https://codecov.io/gh/webpack-contrib/sass-loader
|
|
287
|
-
|
|
288
580
|
[chat]: https://badges.gitter.im/webpack/webpack.svg
|
|
289
581
|
[chat-url]: https://gitter.im/webpack/webpack
|
|
582
|
+
[size]: https://packagephobia.now.sh/badge?p=css-loader
|
|
583
|
+
[size-url]: https://packagephobia.now.sh/result?p=css-loader
|