【问题标题】:Cannot add less support to Angular 8不能减少对 Angular 8 的支持
【发布时间】:2020-02-14 02:03:05
【问题描述】:

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

【问题讨论】:

    标签: javascript angular typescript sass less


    【解决方案1】:

    将此添加到您的 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 扩展名,然后再次运行您的服务器

    【讨论】:

      【解决方案2】:
      npm i less --save
      

      应该适合你

      【讨论】:

      • 你可以试试
      • 它当然可以,但我觉得在这种情况下这是一种黑客行为。
      • 为什么你需要安装更少,因为 Angular cli 已经很小心了?
      猜你喜欢
      • 1970-01-01
      • 2014-01-23
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2012-12-19
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多