stylePreprocessorOptions angular 8 [英] stylePreprocessorOptions angular 8

查看:18
本文介绍了stylePreprocessorOptions angular 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 this 添加通过 Angular 8 中的 stylePreprocessorOptions 导入可导入的 scss 文件,但我不断收到找不到它的错误.任何输入都值得赞赏,这个巧妙的技巧非常有用!

I am following this to add importable scss files through stylePreprocessorOptions in Angular 8 but I keep getting the error that it is not being found. Any input is apreciated, this neat trick is very useful!

下面是我的 angular.json

below is my angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "thebearcottages-app": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss",
          "skipTests": true
        },
        "@schematics/angular:class": {
          "skipTests": true
        },
        "@schematics/angular:directive": {
          "skipTests": true
        },
        "@schematics/angular:guard": {
          "skipTests": true
        },
        "@schematics/angular:module": {
          "skipTests": true
        },
        "@schematics/angular:pipe": {
          "skipTests": true
        },
        "@schematics/angular:service": {
          "skipTests": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/thebearcottages-app",
            "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.scss",
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "src/styling/"
              ]
            },
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "thebearcottages-app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "thebearcottages-app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "thebearcottages-app:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "thebearcottages-app:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "thebearcottages-app:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "thebearcottages-app"
}

这是我得到的错误:

./src/app/content-component/gallery/gallery.component.scss 中的错误模块构建失败(来自 ./node_modules/sass-loader/lib/loader.js):

ERROR in ./src/app/content-component/gallery/gallery.component.scss Module build failed (from ./node_modules/sass-loader/lib/loader.js):

@import "网格";^找不到要导入的样式表.╷1 │ @import "网格";│ ^^^^^^╵标准输入 1:9 根样式表在/Users/konstantinurban/Desktop/thebearcottages/src/app/content-component/gallery/gallery.component.scss(第 1 行,第 9 列)

@import "grid"; ^ Can't find stylesheet to import. ╷ 1 │ @import "grid"; │ ^^^^^^ ╵ stdin 1:9 root stylesheet in /Users/konstantinurban/Desktop/thebearcottages/src/app/content-component/gallery/gallery.component.scss (line 1, column 9)

推荐答案

我在使用 Angular 8 启动新应用程序时发现了同样的错误.它说找不到要导入的样式表".即使是正确申报的进口.经过小调查,我发现它与 sass-loader 错误 https://github.com/webpack-contrib/sass-loader/issues/704我希望它会尽快修复,但同时有一个解决方法:

I found same bug when started new app with Angular 8. It says "Can't find stylesheet to import." even for properly declared imports. After small investigation i found that it is related to sass-loader bug https://github.com/webpack-contrib/sass-loader/issues/704 I hope it will be fixed soon, but meanwhile there is a workaround:

对于 stylePreprocessorOptions/includePaths 中现有的 _mixins.scss,使用包含第一个下划线的文件名

For existing _mixins.scss in your stylePreprocessorOptions / includePaths, use filename including first underscore

@import '_mixins';

而不是更漂亮,但目前有问题

instead of more pretty, but currently buggy

@import 'mixins';

这篇关于stylePreprocessorOptions angular 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆