Skip to content

Commit 9797305

Browse files
committedMar 6, 2024·
refactor(@angular-devkit/build-angular): remove Sass legacy implementation
This commit removes the legacy Sass implementation previously used with Webpack. BREAKING CHANGE: The support for the legacy Sass build pipeline, previously accessible via `NG_BUILD_LEGACY_SASS` when utilizing webpack-based builders, has been removed.
1 parent 714bc22 commit 9797305

File tree

5 files changed

+23
-461
lines changed

5 files changed

+23
-461
lines changed
 

‎packages/angular_devkit/build_angular/src/tools/sass/sass-service-legacy.ts

-251
This file was deleted.

‎packages/angular_devkit/build_angular/src/tools/sass/worker-legacy.ts

-69
This file was deleted.

‎packages/angular_devkit/build_angular/src/tools/webpack/configs/styles.ts

+23-57
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
1212
import type { FileImporter } from 'sass';
1313
import type { Configuration, LoaderContext, RuleSetUseItem } from 'webpack';
1414
import { WebpackConfigOptions } from '../../../utils/build-options';
15-
import { useLegacySass } from '../../../utils/environment-options';
1615
import { findTailwindConfigurationFile } from '../../../utils/tailwind';
1716
import { SassWorkerImplementation } from '../../sass/sass-service';
18-
import { SassLegacyWorkerImplementation } from '../../sass/sass-service-legacy';
1917
import {
2018
AnyComponentStyleBudgetChecker,
2119
PostcssCliResources,
@@ -63,9 +61,7 @@ export async function getStylesConfig(wco: WebpackConfigOptions): Promise<Config
6361
}
6462
}
6563

66-
const sassImplementation = useLegacySass
67-
? new SassLegacyWorkerImplementation()
68-
: new SassWorkerImplementation();
64+
const sassImplementation = new SassWorkerImplementation();
6965

7066
extraPlugins.push({
7167
apply(compiler) {
@@ -314,63 +310,33 @@ export async function getStylesConfig(wco: WebpackConfigOptions): Promise<Config
314310

315311
function getSassLoaderOptions(
316312
root: string,
317-
implementation: SassWorkerImplementation | SassLegacyWorkerImplementation,
313+
implementation: SassWorkerImplementation,
318314
includePaths: string[],
319315
indentedSyntax: boolean,
320316
verbose: boolean,
321317
preserveSymlinks: boolean,
322318
): Record<string, unknown> {
323-
return implementation instanceof SassWorkerImplementation
324-
? {
325-
sourceMap: true,
326-
api: 'modern',
327-
implementation,
328-
// Webpack importer is only implemented in the legacy API and we have our own custom Webpack importer.
329-
// See: https://github.com/webpack-contrib/sass-loader/blob/997f3eb41d86dd00d5fa49c395a1aeb41573108c/src/utils.js#L642-L651
330-
webpackImporter: false,
331-
sassOptions: (loaderContext: LoaderContext<{}>) => ({
332-
importers: [getSassResolutionImporter(loaderContext, root, preserveSymlinks)],
333-
loadPaths: includePaths,
334-
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
335-
// Ex: /* autoprefixer grid: autoplace */
336-
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
337-
style: 'expanded',
338-
// Silences compiler warnings from 3rd party stylesheets
339-
quietDeps: !verbose,
340-
verbose,
341-
syntax: indentedSyntax ? 'indented' : 'scss',
342-
sourceMapIncludeSources: true,
343-
}),
344-
}
345-
: {
346-
sourceMap: true,
347-
api: 'legacy',
348-
implementation,
349-
sassOptions: {
350-
importer: (url: string, from: string) => {
351-
if (url.charAt(0) === '~') {
352-
throw new Error(
353-
`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is no longer supported.`,
354-
);
355-
}
356-
357-
return null;
358-
},
359-
// Prevent use of `fibers` package as it no longer works in newer Node.js versions
360-
fiber: false,
361-
indentedSyntax,
362-
// bootstrap-sass requires a minimum precision of 8
363-
precision: 8,
364-
includePaths,
365-
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
366-
// Ex: /* autoprefixer grid: autoplace */
367-
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
368-
outputStyle: 'expanded',
369-
// Silences compiler warnings from 3rd party stylesheets
370-
quietDeps: !verbose,
371-
verbose,
372-
},
373-
};
319+
return {
320+
sourceMap: true,
321+
api: 'modern',
322+
implementation,
323+
// Webpack importer is only implemented in the legacy API and we have our own custom Webpack importer.
324+
// See: https://github.com/webpack-contrib/sass-loader/blob/997f3eb41d86dd00d5fa49c395a1aeb41573108c/src/utils.js#L642-L651
325+
webpackImporter: false,
326+
sassOptions: (loaderContext: LoaderContext<{}>) => ({
327+
importers: [getSassResolutionImporter(loaderContext, root, preserveSymlinks)],
328+
loadPaths: includePaths,
329+
// Use expanded as otherwise sass will remove comments that are needed for autoprefixer
330+
// Ex: /* autoprefixer grid: autoplace */
331+
// See: https://github.com/webpack-contrib/sass-loader/blob/45ad0be17264ceada5f0b4fb87e9357abe85c4ff/src/getSassOptions.js#L68-L70
332+
style: 'expanded',
333+
// Silences compiler warnings from 3rd party stylesheets
334+
quietDeps: !verbose,
335+
verbose,
336+
syntax: indentedSyntax ? 'indented' : 'scss',
337+
sourceMapIncludeSources: true,
338+
}),
339+
};
374340
}
375341

376342
function getSassResolutionImporter(

‎packages/angular_devkit/build_angular/src/utils/environment-options.ts

-18
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { colors } from './color';
10-
119
function isDisabled(variable: string): boolean {
1210
return variable === '0' || variable.toLowerCase() === 'false';
1311
}
@@ -81,22 +79,6 @@ export const maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable :
8179
const parallelTsVariable = process.env['NG_BUILD_PARALLEL_TS'];
8280
export const useParallelTs = !isPresent(parallelTsVariable) || !isDisabled(parallelTsVariable);
8381

84-
const legacySassVariable = process.env['NG_BUILD_LEGACY_SASS'];
85-
export const useLegacySass: boolean = (() => {
86-
if (!isPresent(legacySassVariable)) {
87-
return false;
88-
}
89-
90-
// eslint-disable-next-line no-console
91-
console.warn(
92-
colors.yellow(
93-
`Warning: 'NG_BUILD_LEGACY_SASS' environment variable support will be removed in version 16.`,
94-
),
95-
);
96-
97-
return isEnabled(legacySassVariable);
98-
})();
99-
10082
const debugPerfVariable = process.env['NG_BUILD_DEBUG_PERF'];
10183
export const debugPerformance = isPresent(debugPerfVariable) && isEnabled(debugPerfVariable);
10284

‎tests/legacy-cli/e2e/tests/build/styles/scss-legacy.ts

-66
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.