无法添加 less 支持 Angular 8

Cannot add less support to Angular 8

我正在尝试为 Angular 8 项目添加 LESS 支持(该项目是通过 ng update 将 SCSS 作为默认样式库从版本 5 更新的。现在我需要将 SCSS 替换为 LESS。只需将 styleext 部分更改为 less 不起作用 - 我收到错误 Error: Cannot find module 'less'。 如何解决?

npm i less --save

应该适合你

将此添加到您的 angular.json

"projects": {
    "sometest": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": { // this one
          "style": "less"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/sometest",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.less" // also this
            ],
            "scripts": []
          },

同时将所有样式更改为 .less 扩展名,然后 运行 再次更改服务器