sass-loader 16.0.8 → 17.0.1
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/README.md +208 -104
- package/dist/cjs/index.js +82 -0
- package/dist/{options.json → cjs/options.json} +3 -3
- package/dist/cjs/package.json +1 -0
- package/dist/{utils.js → cjs/utils.js} +347 -326
- package/dist/esm/index.js +75 -0
- package/dist/esm/options.json +64 -0
- package/dist/esm/utils.js +743 -0
- package/package.json +55 -66
- package/types/index.d.ts +19 -0
- package/types/utils.d.ts +323 -0
- package/dist/cjs.js +0 -4
- package/dist/index.js +0 -103
package/README.md
CHANGED
|
@@ -41,9 +41,11 @@ pnpm add -D sass-loader sass webpack
|
|
|
41
41
|
|
|
42
42
|
> [!NOTE]
|
|
43
43
|
>
|
|
44
|
-
>
|
|
44
|
+
> Webpack has [built-in CSS support](https://webpack.js.org/configuration/experiments/#experimentscss), so no extra loaders are required to process the CSS generated by `sass-loader` - just enable `experiments.css` and set the module `type` to `css/auto`.
|
|
45
|
+
>
|
|
46
|
+
> If you prefer the loader-based setup, install [style-loader](https://webpack.js.org/loaders/style-loader/) and [css-loader](https://webpack.js.org/loaders/css-loader/) via `npm i style-loader css-loader` and chain them with `sass-loader` instead.
|
|
45
47
|
|
|
46
|
-
`sass-loader` requires you to install either [Dart Sass](https://github.com/sass/dart-sass)
|
|
48
|
+
`sass-loader` requires you to install either [Dart Sass](https://github.com/sass/dart-sass) or [Sass Embedded](https://github.com/sass/embedded-host-node) on your own (more documentation can be found below).
|
|
47
49
|
|
|
48
50
|
This allows you to control the versions of all your dependencies and to choose which Sass implementation to use.
|
|
49
51
|
|
|
@@ -51,11 +53,9 @@ This allows you to control the versions of all your dependencies and to choose w
|
|
|
51
53
|
>
|
|
52
54
|
> We highly recommend using [Sass Embedded](https://github.com/sass/embedded-host-node) or [Dart Sass](https://github.com/sass/dart-sass).
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
>
|
|
56
|
-
> [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
|
+
Use the `sass-loader` with the built-in CSS support of webpack (the `css/auto` module type) to let webpack handle the generated CSS - it extracts styles into a separate file and injects them into the document.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Alternatively, you can chain the `sass-loader` with the [css-loader](https://github.com/webpack/css-loader) and the [style-loader](https://github.com/webpack/style-loader) to immediately apply all styles to the DOM, or with the [mini-css-extract-plugin](https://github.com/webpack/mini-css-extract-plugin) to extract it into a separate file.
|
|
59
59
|
|
|
60
60
|
Then add the loader to your webpack configuration. For example:
|
|
61
61
|
|
|
@@ -83,58 +83,141 @@ module.exports = {
|
|
|
83
83
|
rules: [
|
|
84
84
|
{
|
|
85
85
|
test: /\.s[ac]ss$/i,
|
|
86
|
+
// Lets webpack handle the generated CSS using its built-in CSS support,
|
|
87
|
+
// `css/auto` also enables CSS modules for `*.module.scss` files
|
|
88
|
+
type: "css/auto",
|
|
86
89
|
use: [
|
|
87
|
-
// Creates `style` nodes from JS strings
|
|
88
|
-
"style-loader",
|
|
89
|
-
// Translates CSS into CommonJS
|
|
90
|
-
"css-loader",
|
|
91
90
|
// Compiles Sass to CSS
|
|
92
91
|
"sass-loader",
|
|
93
92
|
],
|
|
94
93
|
},
|
|
95
94
|
],
|
|
96
95
|
},
|
|
96
|
+
experiments: {
|
|
97
|
+
// Enables the built-in CSS support of webpack
|
|
98
|
+
css: true,
|
|
99
|
+
},
|
|
97
100
|
};
|
|
98
101
|
```
|
|
99
102
|
|
|
100
103
|
Finally run `webpack` via your preferred method (e.g., via CLI or an npm script).
|
|
101
104
|
|
|
102
|
-
|
|
105
|
+
> [!NOTE]
|
|
106
|
+
>
|
|
107
|
+
> All examples below use the built-in CSS support of webpack.
|
|
108
|
+
> If you use [css-loader](https://github.com/webpack/css-loader) and [style-loader](https://github.com/webpack/style-loader) (or [mini-css-extract-plugin](https://github.com/webpack/mini-css-extract-plugin)) instead, remove the `type` and `experiments` options and put them before the `sass-loader` in the `use` array:
|
|
109
|
+
>
|
|
110
|
+
> ```js
|
|
111
|
+
> module.exports = {
|
|
112
|
+
> module: {
|
|
113
|
+
> rules: [
|
|
114
|
+
> {
|
|
115
|
+
> test: /\.s[ac]ss$/i,
|
|
116
|
+
> use: ["style-loader", "css-loader", "sass-loader"],
|
|
117
|
+
> },
|
|
118
|
+
> ],
|
|
119
|
+
> },
|
|
120
|
+
> };
|
|
121
|
+
> ```
|
|
122
|
+
|
|
123
|
+
### The `style` option in `production` mode
|
|
103
124
|
|
|
104
|
-
For `production` mode, the `style`
|
|
125
|
+
For `production` mode, the `style` option defaults to `compressed` unless otherwise specified in `sassOptions`.
|
|
105
126
|
|
|
106
|
-
### Resolving `import` and `
|
|
127
|
+
### Resolving `import`, `use` and `forward` at-rules
|
|
107
128
|
|
|
108
129
|
Webpack provides an [advanced mechanism to resolve files](https://webpack.js.org/concepts/module-resolution/).
|
|
109
130
|
|
|
110
|
-
The `sass-loader` uses Sass's custom importer feature to pass
|
|
131
|
+
The `sass-loader` uses Sass's custom importer feature to pass every `@use`, `@import` and `@forward` request to the webpack resolving engine, so your webpack [`resolve`](https://webpack.js.org/configuration/resolve/) configuration applies to stylesheets, and you can load Sass modules from `node_modules`:
|
|
132
|
+
|
|
133
|
+
```scss
|
|
134
|
+
@use "bootstrap";
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### How a request is resolved
|
|
138
|
+
|
|
139
|
+
For `@use "theme"` inside `src/app.scss`, the loader asks webpack for the following and takes the first hit:
|
|
140
|
+
|
|
141
|
+
1. the partial `src/_theme.sass`, `src/_theme.scss`, `src/_theme.css`
|
|
142
|
+
2. `src/theme.sass`, `src/theme.scss`, `src/theme.css`
|
|
143
|
+
3. `theme` as written, so aliases and package requests resolve
|
|
144
|
+
|
|
145
|
+
Directories resolve through their `_index`/`index` file. For `@import` only, the import-only files `_theme.import.scss` and `theme.import.scss` are tried before everything else.
|
|
146
|
+
|
|
147
|
+
Relative requests win over module ones, so `@use "theme"` behaves like `@use "./theme"` when both could match. Keeping both `_theme.scss` and `theme.scss` in one directory is ambiguous and Sass reports an error for it, so the order within a directory rarely matters.
|
|
148
|
+
|
|
149
|
+
#### What your `resolve` configuration controls
|
|
150
|
+
|
|
151
|
+
- [`alias`](https://webpack.js.org/configuration/resolve/#resolvealias) - applied to every request, and tried before `node_modules`
|
|
152
|
+
- [`modules`](https://webpack.js.org/configuration/resolve/#resolvemodules) - extra directories to look in, e.g. `src`
|
|
153
|
+
- [`byDependency.sass`](https://webpack.js.org/configuration/resolve/#resolvebydependency) - requests are resolved with `dependencyType: "sass"`, so this targets stylesheets only
|
|
154
|
+
- [`plugins`](https://webpack.js.org/configuration/resolve/#resolveplugins), [`symlinks`](https://webpack.js.org/configuration/resolve/#resolvesymlinks), [`roots`](https://webpack.js.org/configuration/resolve/#resolveroots) and the rest of the resolver options
|
|
155
|
+
|
|
156
|
+
**webpack.config.js**
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
module.exports = {
|
|
160
|
+
resolve: {
|
|
161
|
+
alias: { "@styles": path.resolve(__dirname, "src/styles") },
|
|
162
|
+
modules: [path.resolve(__dirname, "src"), "node_modules"],
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**style.scss**
|
|
168
|
+
|
|
169
|
+
```scss
|
|
170
|
+
@use "@styles/theme" as *; // resolved by `resolve.alias`
|
|
171
|
+
@use "abstracts" as *; // resolved by `resolve.modules` to `src/abstracts/_index.scss`
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Some options are fixed to match Sass's own algorithm and can't be changed through `resolve`: the extensions are `.sass`, `.scss` and `.css` (so [`resolve.extensions`](https://webpack.js.org/configuration/resolve/#resolveextensions) doesn't apply here), `mainFiles` prefer `_index`/`index`, `mainFields` prefer `sass` and `style` over `main`, and `conditionNames` prefer the `sass` and `style` [export conditions](https://webpack.js.org/guides/package-exports/). Your own `mainFields` and `conditionNames` are kept after those.
|
|
175
|
+
|
|
176
|
+
#### Packages
|
|
177
|
+
|
|
178
|
+
A package request resolves through the `sass` and `style` conditions of its `exports` field, falling back to the `sass`, `style` and `main` fields. The [`pkg:` URL scheme](https://sass-lang.com/documentation/at-rules/use/#pkg) is supported as well:
|
|
111
179
|
|
|
112
180
|
```scss
|
|
113
|
-
@
|
|
181
|
+
@use "pkg:bootstrap";
|
|
114
182
|
```
|
|
115
183
|
|
|
184
|
+
#### When webpack can't resolve a request
|
|
185
|
+
|
|
186
|
+
The importer hands the request back to Sass, which then applies its own resolution - [`sassOptions.loadPaths`](#sassoptions), the `SASS_PATH` environment variable and any custom importer you configured.
|
|
187
|
+
|
|
188
|
+
#### Plain CSS files
|
|
189
|
+
|
|
190
|
+
Sass compiles `@import "theme.css"` to a plain CSS `@import`, so the loader leaves it in the output untouched - whatever handles the CSS afterwards (the built-in CSS support of webpack, `css-loader`, or the browser) decides what happens with it. `@use "theme.css"` includes the file's content instead, and is resolved like any other request:
|
|
191
|
+
|
|
192
|
+
```scss
|
|
193
|
+
@import "theme.css"; // stays `@import "theme.css";` in the output
|
|
194
|
+
@use "theme.css"; // inlines the content of the file
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### The `~` prefix
|
|
198
|
+
|
|
116
199
|
Using `~` is deprecated and should be removed from your code, but we still support it for historical reasons.
|
|
117
200
|
|
|
118
|
-
Why can you remove it? The loader will first try to resolve `@
|
|
201
|
+
Why can you remove it? The loader will first try to resolve `@use` as a relative path. If it cannot be resolved, then the loader will try to resolve it inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
|
|
119
202
|
|
|
120
203
|
Prepending module paths with a `~` tells webpack to search through [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
|
|
121
204
|
|
|
122
205
|
```scss
|
|
123
|
-
@
|
|
206
|
+
@use "~bootstrap";
|
|
124
207
|
```
|
|
125
208
|
|
|
126
209
|
It's important to prepend the path with only `~`, because `~/` resolves to the home directory.
|
|
127
210
|
|
|
128
211
|
Webpack needs to distinguish between `bootstrap` and `~bootstrap` because CSS and Sass files have no special syntax for importing relative files.
|
|
129
212
|
|
|
130
|
-
Writing `@
|
|
213
|
+
Writing `@use "style.scss"` is the same as `@use "./style.scss";`
|
|
131
214
|
|
|
132
215
|
### Problems with `url(...)`
|
|
133
216
|
|
|
134
217
|
Since Sass implementations don't provide [url rewriting](https://github.com/sass/libsass/issues/532), all linked assets must be relative to the output.
|
|
135
218
|
|
|
136
|
-
- If
|
|
137
|
-
- If you're just generating CSS without
|
|
219
|
+
- If webpack handles the generated CSS (i.e. the built-in CSS support or the `css-loader`), all URLs must be relative to the entry-file (e.g. `main.scss`).
|
|
220
|
+
- If you're just generating CSS without letting webpack handle it, URLs must be relative to your web root.
|
|
138
221
|
|
|
139
222
|
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).
|
|
140
223
|
|
|
@@ -167,7 +250,7 @@ Default: `sass`
|
|
|
167
250
|
The special `implementation` option determines which implementation of Sass to use.
|
|
168
251
|
|
|
169
252
|
By default, the loader resolves the implementation based on your dependencies.
|
|
170
|
-
Just add the desired implementation to your `package.json` (`sass
|
|
253
|
+
Just add the desired implementation to your `package.json` (`sass` or `sass-embedded` package) and install dependencies.
|
|
171
254
|
|
|
172
255
|
Example where the `sass-loader` uses the `sass` (`dart-sass`) implementation:
|
|
173
256
|
|
|
@@ -182,19 +265,6 @@ Example where the `sass-loader` uses the `sass` (`dart-sass`) implementation:
|
|
|
182
265
|
}
|
|
183
266
|
```
|
|
184
267
|
|
|
185
|
-
Example where the `sass-loader` uses the `node-sass` implementation:
|
|
186
|
-
|
|
187
|
-
**package.json**
|
|
188
|
-
|
|
189
|
-
```json
|
|
190
|
-
{
|
|
191
|
-
"devDependencies": {
|
|
192
|
-
"sass-loader": "^7.2.0",
|
|
193
|
-
"node-sass": "^5.0.0"
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
268
|
Example where the `sass-loader` uses the `sass-embedded` implementation:
|
|
199
269
|
|
|
200
270
|
**package.json**
|
|
@@ -219,7 +289,6 @@ Be aware of the order that `sass-loader` will resolve the implementation:
|
|
|
219
289
|
|
|
220
290
|
1. `sass-embedded`
|
|
221
291
|
2. `sass`
|
|
222
|
-
3. `node-sass`
|
|
223
292
|
|
|
224
293
|
You can specify a specific implementation by using the `implementation` option, which accepts one of the above values.
|
|
225
294
|
|
|
@@ -233,9 +302,8 @@ module.exports = {
|
|
|
233
302
|
rules: [
|
|
234
303
|
{
|
|
235
304
|
test: /\.s[ac]ss$/i,
|
|
305
|
+
type: "css/auto",
|
|
236
306
|
use: [
|
|
237
|
-
"style-loader",
|
|
238
|
-
"css-loader",
|
|
239
307
|
{
|
|
240
308
|
loader: "sass-loader",
|
|
241
309
|
options: {
|
|
@@ -247,6 +315,9 @@ module.exports = {
|
|
|
247
315
|
},
|
|
248
316
|
],
|
|
249
317
|
},
|
|
318
|
+
experiments: {
|
|
319
|
+
css: true,
|
|
320
|
+
},
|
|
250
321
|
};
|
|
251
322
|
```
|
|
252
323
|
|
|
@@ -260,9 +331,8 @@ module.exports = {
|
|
|
260
331
|
rules: [
|
|
261
332
|
{
|
|
262
333
|
test: /\.s[ac]ss$/i,
|
|
334
|
+
type: "css/auto",
|
|
263
335
|
use: [
|
|
264
|
-
"style-loader",
|
|
265
|
-
"css-loader",
|
|
266
336
|
{
|
|
267
337
|
loader: "sass-loader",
|
|
268
338
|
options: {
|
|
@@ -274,6 +344,9 @@ module.exports = {
|
|
|
274
344
|
},
|
|
275
345
|
],
|
|
276
346
|
},
|
|
347
|
+
experiments: {
|
|
348
|
+
css: true,
|
|
349
|
+
},
|
|
277
350
|
};
|
|
278
351
|
```
|
|
279
352
|
|
|
@@ -283,17 +356,17 @@ Type:
|
|
|
283
356
|
|
|
284
357
|
```ts
|
|
285
358
|
type sassOptions =
|
|
286
|
-
| import("sass").
|
|
359
|
+
| import("sass").StringOptionsWithImporter<"async">
|
|
287
360
|
| ((
|
|
288
361
|
content: string | Buffer,
|
|
289
362
|
loaderContext: LoaderContext,
|
|
290
363
|
meta: any,
|
|
291
|
-
) => import("sass").
|
|
364
|
+
) => import("sass").StringOptionsWithImporter<"async">);
|
|
292
365
|
```
|
|
293
366
|
|
|
294
367
|
Default: defaults values for Sass implementation
|
|
295
368
|
|
|
296
|
-
Options for [Dart Sass](http://sass-lang.com/dart-sass) or [
|
|
369
|
+
Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Sass Embedded](https://github.com/sass/embedded-host-node) implementation.
|
|
297
370
|
|
|
298
371
|
> [!NOTE]
|
|
299
372
|
>
|
|
@@ -301,25 +374,18 @@ Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://g
|
|
|
301
374
|
|
|
302
375
|
> [!NOTE]
|
|
303
376
|
>
|
|
304
|
-
> The `syntax`
|
|
377
|
+
> The `syntax` option is `scss` for the `scss` extension, `indented` for the `sass` extension, and `css` for the `css` extension.
|
|
305
378
|
|
|
306
379
|
> [!NOTE]
|
|
307
380
|
>
|
|
308
|
-
> Options such as `data` and `
|
|
381
|
+
> Options such as `data` and `url` are unavailable and will be ignored.
|
|
309
382
|
|
|
310
|
-
> ℹ We strongly discourage changing the `sourceMap`
|
|
311
|
-
|
|
312
|
-
> [!NOTE]
|
|
313
|
-
>
|
|
314
|
-
> Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside the custom importer can be done using the `this.webpackLoaderContext` property.
|
|
315
|
-
|
|
316
|
-
There is a slight difference between the options for `sass` (`dart-sass`) and `node-sass`.
|
|
383
|
+
> ℹ We strongly discourage changing the `sourceMap` option because `sass-loader` sets it automatically when the `sourceMap` option is `true`.
|
|
317
384
|
|
|
318
385
|
Please consult their respective documentation before using them:
|
|
319
386
|
|
|
320
387
|
- [Dart Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options) for all available `sass` options.
|
|
321
|
-
- [Sass Embedded documentation](https://github.com/sass/embedded-host-node) for all available `sass` options.
|
|
322
|
-
- [Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
|
|
388
|
+
- [Sass Embedded documentation](https://github.com/sass/embedded-host-node) for all available `sass-embedded` options.
|
|
323
389
|
|
|
324
390
|
#### `object`
|
|
325
391
|
|
|
@@ -333,9 +399,8 @@ module.exports = {
|
|
|
333
399
|
rules: [
|
|
334
400
|
{
|
|
335
401
|
test: /\.s[ac]ss$/i,
|
|
402
|
+
type: "css/auto",
|
|
336
403
|
use: [
|
|
337
|
-
"style-loader",
|
|
338
|
-
"css-loader",
|
|
339
404
|
{
|
|
340
405
|
loader: "sass-loader",
|
|
341
406
|
options: {
|
|
@@ -349,6 +414,9 @@ module.exports = {
|
|
|
349
414
|
},
|
|
350
415
|
],
|
|
351
416
|
},
|
|
417
|
+
experiments: {
|
|
418
|
+
css: true,
|
|
419
|
+
},
|
|
352
420
|
};
|
|
353
421
|
```
|
|
354
422
|
|
|
@@ -362,9 +430,8 @@ module.exports = {
|
|
|
362
430
|
rules: [
|
|
363
431
|
{
|
|
364
432
|
test: /\.s[ac]ss$/i,
|
|
433
|
+
type: "css/auto",
|
|
365
434
|
use: [
|
|
366
|
-
"style-loader",
|
|
367
|
-
"css-loader",
|
|
368
435
|
{
|
|
369
436
|
loader: "sass-loader",
|
|
370
437
|
options: {
|
|
@@ -389,6 +456,9 @@ module.exports = {
|
|
|
389
456
|
},
|
|
390
457
|
],
|
|
391
458
|
},
|
|
459
|
+
experiments: {
|
|
460
|
+
css: true,
|
|
461
|
+
},
|
|
392
462
|
};
|
|
393
463
|
```
|
|
394
464
|
|
|
@@ -407,7 +477,7 @@ Enables/disables generation of source maps.
|
|
|
407
477
|
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
|
|
408
478
|
All values enable source map generation except `eval` and `false`.
|
|
409
479
|
|
|
410
|
-
> ℹ If `true`, the `sourceMap`
|
|
480
|
+
> ℹ If `true`, the `sourceMap` option from `sassOptions` will be ignored.
|
|
411
481
|
|
|
412
482
|
**webpack.config.js**
|
|
413
483
|
|
|
@@ -417,14 +487,8 @@ module.exports = {
|
|
|
417
487
|
rules: [
|
|
418
488
|
{
|
|
419
489
|
test: /\.s[ac]ss$/i,
|
|
490
|
+
type: "css/auto",
|
|
420
491
|
use: [
|
|
421
|
-
"style-loader",
|
|
422
|
-
{
|
|
423
|
-
loader: "css-loader",
|
|
424
|
-
options: {
|
|
425
|
-
sourceMap: true,
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
492
|
{
|
|
429
493
|
loader: "sass-loader",
|
|
430
494
|
options: {
|
|
@@ -435,13 +499,12 @@ module.exports = {
|
|
|
435
499
|
},
|
|
436
500
|
],
|
|
437
501
|
},
|
|
502
|
+
experiments: {
|
|
503
|
+
css: true,
|
|
504
|
+
},
|
|
438
505
|
};
|
|
439
506
|
```
|
|
440
507
|
|
|
441
|
-
> ℹ In some rare cases `node-sass` can output invalid source maps (this is a `node-sass` bug).
|
|
442
|
-
>
|
|
443
|
-
> 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`.
|
|
444
|
-
|
|
445
508
|
**webpack.config.js**
|
|
446
509
|
|
|
447
510
|
```js
|
|
@@ -450,15 +513,14 @@ module.exports = {
|
|
|
450
513
|
rules: [
|
|
451
514
|
{
|
|
452
515
|
test: /\.s[ac]ss$/i,
|
|
516
|
+
type: "css/auto",
|
|
453
517
|
use: [
|
|
454
|
-
"style-loader",
|
|
455
|
-
"css-loader",
|
|
456
518
|
{
|
|
457
519
|
loader: "sass-loader",
|
|
458
520
|
options: {
|
|
459
521
|
sourceMap: true,
|
|
460
522
|
sassOptions: {
|
|
461
|
-
|
|
523
|
+
style: "compressed",
|
|
462
524
|
},
|
|
463
525
|
},
|
|
464
526
|
},
|
|
@@ -466,6 +528,9 @@ module.exports = {
|
|
|
466
528
|
},
|
|
467
529
|
],
|
|
468
530
|
},
|
|
531
|
+
experiments: {
|
|
532
|
+
css: true,
|
|
533
|
+
},
|
|
469
534
|
};
|
|
470
535
|
```
|
|
471
536
|
|
|
@@ -494,9 +559,8 @@ module.exports = {
|
|
|
494
559
|
rules: [
|
|
495
560
|
{
|
|
496
561
|
test: /\.s[ac]ss$/i,
|
|
562
|
+
type: "css/auto",
|
|
497
563
|
use: [
|
|
498
|
-
"style-loader",
|
|
499
|
-
"css-loader",
|
|
500
564
|
{
|
|
501
565
|
loader: "sass-loader",
|
|
502
566
|
options: {
|
|
@@ -507,6 +571,9 @@ module.exports = {
|
|
|
507
571
|
},
|
|
508
572
|
],
|
|
509
573
|
},
|
|
574
|
+
experiments: {
|
|
575
|
+
css: true,
|
|
576
|
+
},
|
|
510
577
|
};
|
|
511
578
|
```
|
|
512
579
|
|
|
@@ -520,9 +587,8 @@ module.exports = {
|
|
|
520
587
|
rules: [
|
|
521
588
|
{
|
|
522
589
|
test: /\.s[ac]ss$/i,
|
|
590
|
+
type: "css/auto",
|
|
523
591
|
use: [
|
|
524
|
-
"style-loader",
|
|
525
|
-
"css-loader",
|
|
526
592
|
{
|
|
527
593
|
loader: "sass-loader",
|
|
528
594
|
options: {
|
|
@@ -543,6 +609,9 @@ module.exports = {
|
|
|
543
609
|
},
|
|
544
610
|
],
|
|
545
611
|
},
|
|
612
|
+
experiments: {
|
|
613
|
+
css: true,
|
|
614
|
+
},
|
|
546
615
|
};
|
|
547
616
|
```
|
|
548
617
|
|
|
@@ -554,9 +623,8 @@ module.exports = {
|
|
|
554
623
|
rules: [
|
|
555
624
|
{
|
|
556
625
|
test: /\.s[ac]ss$/i,
|
|
626
|
+
type: "css/auto",
|
|
557
627
|
use: [
|
|
558
|
-
"style-loader",
|
|
559
|
-
"css-loader",
|
|
560
628
|
{
|
|
561
629
|
loader: "sass-loader",
|
|
562
630
|
options: {
|
|
@@ -577,6 +645,9 @@ module.exports = {
|
|
|
577
645
|
},
|
|
578
646
|
],
|
|
579
647
|
},
|
|
648
|
+
experiments: {
|
|
649
|
+
css: true,
|
|
650
|
+
},
|
|
580
651
|
};
|
|
581
652
|
```
|
|
582
653
|
|
|
@@ -593,7 +664,7 @@ Default: `true`
|
|
|
593
664
|
Enables/disables the default webpack importer.
|
|
594
665
|
|
|
595
666
|
This can improve performance in some cases, though use it with caution because aliases and `@import` at-rules starting with `~` will not work.
|
|
596
|
-
You can pass your own `importer` to solve this (see [
|
|
667
|
+
You can pass your own `importer` to solve this (see [Sass importer documentation](https://sass-lang.com/documentation/js-api/interfaces/LegacyImporter)).
|
|
597
668
|
|
|
598
669
|
**webpack.config.js**
|
|
599
670
|
|
|
@@ -603,9 +674,8 @@ module.exports = {
|
|
|
603
674
|
rules: [
|
|
604
675
|
{
|
|
605
676
|
test: /\.s[ac]ss$/i,
|
|
677
|
+
type: "css/auto",
|
|
606
678
|
use: [
|
|
607
|
-
"style-loader",
|
|
608
|
-
"css-loader",
|
|
609
679
|
{
|
|
610
680
|
loader: "sass-loader",
|
|
611
681
|
options: {
|
|
@@ -616,6 +686,9 @@ module.exports = {
|
|
|
616
686
|
},
|
|
617
687
|
],
|
|
618
688
|
},
|
|
689
|
+
experiments: {
|
|
690
|
+
css: true,
|
|
691
|
+
},
|
|
619
692
|
};
|
|
620
693
|
```
|
|
621
694
|
|
|
@@ -665,9 +738,8 @@ module.exports = {
|
|
|
665
738
|
rules: [
|
|
666
739
|
{
|
|
667
740
|
test: /\.s[ac]ss$/i,
|
|
741
|
+
type: "css/auto",
|
|
668
742
|
use: [
|
|
669
|
-
"style-loader",
|
|
670
|
-
"css-loader",
|
|
671
743
|
{
|
|
672
744
|
loader: "sass-loader",
|
|
673
745
|
options: {
|
|
@@ -678,6 +750,9 @@ module.exports = {
|
|
|
678
750
|
},
|
|
679
751
|
],
|
|
680
752
|
},
|
|
753
|
+
experiments: {
|
|
754
|
+
css: true,
|
|
755
|
+
},
|
|
681
756
|
};
|
|
682
757
|
```
|
|
683
758
|
|
|
@@ -686,20 +761,22 @@ module.exports = {
|
|
|
686
761
|
Type:
|
|
687
762
|
|
|
688
763
|
```ts
|
|
689
|
-
type api = "
|
|
764
|
+
type api = "auto" | "modern" | "modern-compiler";
|
|
690
765
|
```
|
|
691
766
|
|
|
692
|
-
Default: `"
|
|
767
|
+
Default: `"auto"` for `sass` (`dart-sass`) and `sass-embedded`
|
|
768
|
+
|
|
769
|
+
Allows you to switch between the `modern` and `modern-compiler` APIs. You can find more information [here](https://sass-lang.com/documentation/js-api). The `modern-compiler` option enables the modern API with support for [Shared Resources](https://github.com/sass/sass/blob/main/accepted/shared-resources.d.ts.md).
|
|
693
770
|
|
|
694
|
-
|
|
771
|
+
When `"auto"` is used, the loader picks `"modern-compiler"` whenever the implementation exposes `initAsyncCompiler` (i.e. recent versions of `sass` and `sass-embedded`) and falls back to `"modern"` otherwise. Combined with `sass-embedded`, this yields the best build performance out of the box.
|
|
695
772
|
|
|
696
773
|
> [!NOTE]
|
|
697
774
|
>
|
|
698
|
-
> Using `modern-compiler` and `sass-embedded` together significantly improves performance and decreases build time.
|
|
775
|
+
> Using `modern-compiler` and `sass-embedded` together significantly improves performance and decreases build time. They are now selected automatically by the default `"auto"` API.
|
|
699
776
|
|
|
700
|
-
> [!
|
|
777
|
+
> [!NOTE]
|
|
701
778
|
>
|
|
702
|
-
> The Sass
|
|
779
|
+
> The legacy Sass JS API is no longer supported. If you were using `api: "legacy"`, please migrate to the modern API. See the [Sass JS API docs](https://sass-lang.com/documentation/js-api) to learn how to migrate.
|
|
703
780
|
|
|
704
781
|
**webpack.config.js**
|
|
705
782
|
|
|
@@ -709,9 +786,8 @@ module.exports = {
|
|
|
709
786
|
rules: [
|
|
710
787
|
{
|
|
711
788
|
test: /\.s[ac]ss$/i,
|
|
789
|
+
type: "css/auto",
|
|
712
790
|
use: [
|
|
713
|
-
"style-loader",
|
|
714
|
-
"css-loader",
|
|
715
791
|
{
|
|
716
792
|
loader: "sass-loader",
|
|
717
793
|
options: {
|
|
@@ -725,6 +801,9 @@ module.exports = {
|
|
|
725
801
|
},
|
|
726
802
|
],
|
|
727
803
|
},
|
|
804
|
+
experiments: {
|
|
805
|
+
css: true,
|
|
806
|
+
},
|
|
728
807
|
};
|
|
729
808
|
```
|
|
730
809
|
|
|
@@ -748,9 +827,37 @@ module.exports = {
|
|
|
748
827
|
|
|
749
828
|
For production builds, it's recommended to extract the CSS from your bundle to enable parallel loading of CSS/JS resources.
|
|
750
829
|
|
|
751
|
-
There are
|
|
830
|
+
There are five recommended ways to extract a stylesheet from a bundle:
|
|
831
|
+
|
|
832
|
+
#### 1. [Built-in CSS support](https://webpack.js.org/configuration/experiments/#experimentscss)
|
|
833
|
+
|
|
834
|
+
Webpack emits CSS into separate files on its own, so nothing but `experiments.css` is required.
|
|
835
|
+
|
|
836
|
+
**webpack.config.js**
|
|
837
|
+
|
|
838
|
+
```js
|
|
839
|
+
module.exports = {
|
|
840
|
+
module: {
|
|
841
|
+
rules: [
|
|
842
|
+
{
|
|
843
|
+
test: /\.s[ac]ss$/i,
|
|
844
|
+
type: "css/auto",
|
|
845
|
+
use: ["sass-loader"],
|
|
846
|
+
},
|
|
847
|
+
],
|
|
848
|
+
},
|
|
849
|
+
output: {
|
|
850
|
+
// Both options are optional
|
|
851
|
+
cssFilename: "[name].css",
|
|
852
|
+
cssChunkFilename: "[id].css",
|
|
853
|
+
},
|
|
854
|
+
experiments: {
|
|
855
|
+
css: true,
|
|
856
|
+
},
|
|
857
|
+
};
|
|
858
|
+
```
|
|
752
859
|
|
|
753
|
-
####
|
|
860
|
+
#### 2. [mini-css-extract-plugin](https://github.com/webpack/mini-css-extract-plugin)
|
|
754
861
|
|
|
755
862
|
**webpack.config.js**
|
|
756
863
|
|
|
@@ -784,7 +891,7 @@ module.exports = {
|
|
|
784
891
|
};
|
|
785
892
|
```
|
|
786
893
|
|
|
787
|
-
####
|
|
894
|
+
#### 3. [Asset Modules](https://webpack.js.org/guides/asset-modules/)
|
|
788
895
|
|
|
789
896
|
**webpack.config.js**
|
|
790
897
|
|
|
@@ -814,9 +921,9 @@ module.exports = {
|
|
|
814
921
|
};
|
|
815
922
|
```
|
|
816
923
|
|
|
817
|
-
####
|
|
924
|
+
#### 4. [extract-loader](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
|
|
818
925
|
|
|
819
|
-
####
|
|
926
|
+
#### 5. [file-loader](https://github.com/webpack-contrib/file-loader) (deprecated--should only be used in webpack v4)
|
|
820
927
|
|
|
821
928
|
**webpack.config.js**
|
|
822
929
|
|
|
@@ -854,7 +961,7 @@ module.exports = {
|
|
|
854
961
|
|
|
855
962
|
Enables/disables generation of source maps.
|
|
856
963
|
|
|
857
|
-
To enable CSS source maps, you'll need to pass the `sourceMap` option to
|
|
964
|
+
To enable CSS source maps, you'll need to pass the `sourceMap` option to the `sass-loader` (and to the `css-loader` too, when you use it).
|
|
858
965
|
|
|
859
966
|
**webpack.config.js**
|
|
860
967
|
|
|
@@ -865,14 +972,8 @@ module.exports = {
|
|
|
865
972
|
rules: [
|
|
866
973
|
{
|
|
867
974
|
test: /\.s[ac]ss$/i,
|
|
975
|
+
type: "css/auto",
|
|
868
976
|
use: [
|
|
869
|
-
"style-loader",
|
|
870
|
-
{
|
|
871
|
-
loader: "css-loader",
|
|
872
|
-
options: {
|
|
873
|
-
sourceMap: true,
|
|
874
|
-
},
|
|
875
|
-
},
|
|
876
977
|
{
|
|
877
978
|
loader: "sass-loader",
|
|
878
979
|
options: {
|
|
@@ -883,6 +984,9 @@ module.exports = {
|
|
|
883
984
|
},
|
|
884
985
|
],
|
|
885
986
|
},
|
|
987
|
+
experiments: {
|
|
988
|
+
css: true,
|
|
989
|
+
},
|
|
886
990
|
};
|
|
887
991
|
```
|
|
888
992
|
|