Skip to content

Commit 529c02f

Browse files
feat!: remove legacy Sass JS API support (#1314)
1 parent a337219 commit 529c02f

24 files changed

Lines changed: 322663 additions & 775083 deletions

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ module.exports = {
9595

9696
Finally run `webpack` via your preferred method (e.g., via CLI or an npm script).
9797

98-
### The `style` (new API, by default since 16 version) and `outputStyle` (old API) options in `production` mode
98+
### The `style` option in `production` mode
9999

100-
For `production` mode, the `style` (new API, by default since 16 version) and `outputStyle` (old API) options default to `compressed` unless otherwise specified in `sassOptions`.
100+
For `production` mode, the `style` option defaults to `compressed` unless otherwise specified in `sassOptions`.
101101

102102
### Resolving `import` and `use` at-rules
103103

@@ -265,12 +265,12 @@ Type:
265265

266266
```ts
267267
type sassOptions =
268-
| import("sass").LegacyOptions<"async">
268+
| import("sass").StringOptionsWithImporter<"async">
269269
| ((
270270
content: string | Buffer,
271271
loaderContext: LoaderContext,
272272
meta: any,
273-
) => import("sass").LegacyOptions<"async">);
273+
) => import("sass").StringOptionsWithImporter<"async">);
274274
```
275275

276276
Default: defaults values for Sass implementation
@@ -283,17 +283,13 @@ Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Sass Embedded](https
283283
284284
> [!NOTE]
285285
>
286-
> 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.
286+
> The `syntax` option is `scss` for the `scss` extension, `indented` for the `sass` extension, and `css` for the `css` extension.
287287
288288
> [!NOTE]
289289
>
290-
> Options such as `data` and `file` are unavailable and will be ignored.
290+
> Options such as `data` and `url` are unavailable and will be ignored.
291291
292-
> ℹ We strongly discourage changing the `sourceMap` (new API, by default since 16 version), `outFile` (old API), `sourceMapContents` (old API), `sourceMapEmbed` (old API), and `sourceMapRoot` (old API) options because `sass-loader` sets these automatically when the `sourceMap` option is `true`.
293-
294-
> [!NOTE]
295-
>
296-
> 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.
292+
> ℹ We strongly discourage changing the `sourceMap` option because `sass-loader` sets it automatically when the `sourceMap` option is `true`.
297293
298294
Please consult their respective documentation before using them:
299295

@@ -386,7 +382,7 @@ Enables/disables generation of source maps.
386382
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
387383
All values enable source map generation except `eval` and `false`.
388384

389-
> ℹ If `true`, the `sourceMap` (new API, by default since 16 version), `outFile` (old API), `sourceMapContents` (old API), `sourceMapEmbed` (old API), and `sourceMapRoot` (old API) from `sassOptions` will be ignored.
385+
> ℹ If `true`, the `sourceMap` option from `sassOptions` will be ignored.
390386
391387
**webpack.config.js**
392388

@@ -433,7 +429,7 @@ module.exports = {
433429
options: {
434430
sourceMap: true,
435431
sassOptions: {
436-
outputStyle: "compressed",
432+
style: "compressed",
437433
},
438434
},
439435
},
@@ -661,20 +657,20 @@ module.exports = {
661657
Type:
662658

663659
```ts
664-
type api = "legacy" | "modern" | "modern-compiler";
660+
type api = "modern" | "modern-compiler";
665661
```
666662

667663
Default: `"modern"` for `sass` (`dart-sass`) and `sass-embedded`
668664

669-
Allows you to switch between the `legacy` and `modern` 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).
665+
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).
670666

671667
> [!NOTE]
672668
>
673669
> 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.
674670
675-
> [!WARNING]
671+
> [!NOTE]
676672
>
677-
> 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.
673+
> 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.
678674
679675
**webpack.config.js**
680676

src/index.js

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
getModernWebpackImporter,
99
getSassImplementation,
1010
getSassOptions,
11-
getWebpackImporter,
1211
normalizeSourceMap,
1312
} from "./utils";
1413

@@ -36,15 +35,13 @@ async function loader(content) {
3635

3736
const useSourceMap =
3837
typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
39-
// Use `modern` for `dart-sass` and `sass-embedded` by default
4038
const apiType = typeof options.api === "undefined" ? "modern" : options.api;
4139
const sassOptions = await getSassOptions(
4240
this,
4341
options,
4442
content,
4543
implementation,
4644
useSourceMap,
47-
apiType,
4845
);
4946

5047
const shouldUseWebpackImporter =
@@ -53,20 +50,10 @@ async function loader(content) {
5350
: true;
5451

5552
if (shouldUseWebpackImporter) {
56-
const isModernAPI = apiType === "modern" || apiType === "modern-compiler";
57-
58-
if (!isModernAPI) {
59-
const { includePaths } = sassOptions;
60-
61-
sassOptions.importer.push(
62-
getWebpackImporter(this, implementation, includePaths),
63-
);
64-
} else {
65-
sassOptions.importers.push(
66-
// No need to pass `loadPaths`, because modern API handle them itself
67-
getModernWebpackImporter(this, implementation, []),
68-
);
69-
}
53+
sassOptions.importers.push(
54+
// No need to pass `loadPaths`, because modern API handle them itself
55+
getModernWebpackImporter(this, implementation, []),
56+
);
7057
}
7158

7259
let compile;
@@ -83,32 +70,23 @@ async function loader(content) {
8370
try {
8471
result = await compile(sassOptions);
8572
} catch (error) {
86-
// There are situations when the `file`/`span.url` property do not exist
87-
// Modern API
73+
// There are situations when the `span.url` property does not exist
8874
if (error.span && typeof error.span.url !== "undefined") {
8975
this.addDependency(url.fileURLToPath(error.span.url));
9076
}
91-
// Legacy API
92-
else if (typeof error.file !== "undefined") {
93-
// `sass` returns POSIX paths
94-
this.addDependency(path.normalize(error.file));
95-
}
9677

9778
callback(errorFactory(error));
9879

9980
return;
10081
}
10182

102-
let map =
103-
// Modern API, then legacy API
104-
result.sourceMap || (result.map ? JSON.parse(result.map) : null);
83+
let map = result.sourceMap || null;
10584

10685
// Modify source paths only for webpack, otherwise we do nothing
10786
if (map && useSourceMap) {
10887
map = normalizeSourceMap(map, this.rootContext);
10988
}
11089

111-
// Modern API
11290
if (typeof result.loadedUrls !== "undefined") {
11391
for (const includedFile of result.loadedUrls.filter(
11492
(loadedUrl) => loadedUrl.protocol === "file:",
@@ -121,20 +99,6 @@ async function loader(content) {
12199
}
122100
}
123101
}
124-
// Legacy API
125-
else if (
126-
typeof result.stats !== "undefined" &&
127-
typeof result.stats.includedFiles !== "undefined"
128-
) {
129-
for (const includedFile of result.stats.includedFiles) {
130-
const normalizedIncludedFile = path.normalize(includedFile);
131-
132-
// Custom `importer` can return only `contents` so includedFile will be relative
133-
if (path.isAbsolute(normalizedIncludedFile)) {
134-
this.addDependency(normalizedIncludedFile);
135-
}
136-
}
137-
}
138102

139103
callback(null, result.css.toString(), map);
140104
}

src/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
]
1616
},
1717
"api": {
18-
"description": "Switch between old and modern API for `sass` (`Dart Sass`) and `Sass Embedded` implementations.",
18+
"description": "Switch between `modern` and `modern-compiler` API for `sass` (`Dart Sass`) and `Sass Embedded` implementations.",
1919
"link": "https://github.com/webpack/sass-loader#sassoptions",
20-
"enum": ["legacy", "modern", "modern-compiler"]
20+
"enum": ["modern", "modern-compiler"]
2121
},
2222
"sassOptions": {
2323
"description": "Options for `sass` (`Dart Sass`) or `sass-embedded` implementation.",

0 commit comments

Comments
 (0)