Skip to content

Commit 0a59eae

Browse files
committed
refactor(@angular/build): move less stylesheet preprocessor to an optional peer dependency
The Less stylesheet preprocessor is now an optional peer dependency of the newly introduced `@angular/build` build system package. Less stylesheet usage is currently estimated at less than 10% of projects with analytics enabled. Less stylesheets are still fully supported but usage will now require installing the `less` package within the Angular workspace. An error with instructions to install the package will be generated during a build if the package is not present. This change only affects direct usage of the new `@angular/build` package. The `@angular-devkit/build-angular` package which is currently used for all existing projects will continue to contain and directly depend on the `less` package. No changes are required for existing applications.
1 parent b2ac5fa commit 0a59eae

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/angular/build/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"fast-glob": "3.3.2",
3131
"https-proxy-agent": "7.0.4",
3232
"inquirer": "9.2.19",
33-
"less": "4.2.0",
3433
"magic-string": "0.30.10",
3534
"mrmime": "2.0.0",
3635
"ora": "5.4.1",
@@ -48,6 +47,7 @@
4847
"@angular/localize": "^18.0.0 || ^18.0.0-next.0",
4948
"@angular/platform-server": "^18.0.0 || ^18.0.0-next.0",
5049
"@angular/service-worker": "^18.0.0 || ^18.0.0-next.0",
50+
"less": "^4.2.0",
5151
"tailwindcss": "^2.0.0 || ^3.0.0",
5252
"typescript": ">=5.4 <5.5"
5353
},
@@ -61,6 +61,9 @@
6161
"@angular/service-worker": {
6262
"optional": true
6363
},
64+
"less": {
65+
"optional": true
66+
},
6467
"tailwindcss": {
6568
"optional": true
6669
}

packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,26 @@ async function compileString(
4949
resolver: PluginBuild['resolve'],
5050
unsafeInlineJavaScript: boolean,
5151
): Promise<OnLoadResult> {
52-
const less = (lessPreprocessor ??= (await import('less')).default);
52+
try {
53+
lessPreprocessor ??= (await import('less')).default;
54+
} catch {
55+
return {
56+
errors: [
57+
{
58+
text: 'Unable to load the "less" stylesheet preprocessor.',
59+
location: null,
60+
notes: [
61+
{
62+
text:
63+
'Ensure that the "less" Node.js package is installed within the project. ' +
64+
"If not present, installation via the project's package manager should resolve the error.",
65+
},
66+
],
67+
},
68+
],
69+
};
70+
}
71+
const less = lessPreprocessor;
5372

5473
const resolverPlugin: Less.Plugin = {
5574
install({ FileManager }, pluginManager): void {

0 commit comments

Comments
 (0)