【问题标题】:stylePreprocessorOptions not working on @Angular/cli 7stylePreprocessorOptions 不适用于@Angular/cli 7
【发布时间】:2019-03-29 00:15:07
【问题描述】:

因此,我正在尝试对我的应用进行“白标化”,从而允许为多个客户提供多种设计选项。在我的组件的 scss 中,我需要加载一个位于此“主题”文件夹下的“_variables.scss”,结构如下:

/
- themes
-- client-1
--- _variables.scss
-- client-2
--- _variables.scss

在我的 angular.json 中,我有这个配置:

"projects": {
  "client-1": {
     ...
     "architect": {
       "build": {
         ...
         "options": {
           ...
           "stylePreprocessorOptions": {
             "includePaths": [
               "themes/client-1"
             ]
           },
           "styles": [
             "src/styles.scss",
           ]
           ...
         }
         ...
       }
     },

     "client-2": {
     ...
     "architect": {
       "build": {
         ...
         "options": {
           ...
           "stylePreprocessorOptions": {
             "includePaths": [
               "themes/client-2"
             ]
           },
           "styles": [
             "src/styles.scss",
           ]
           ...
         }
         ...
       }
     }
  }

根据documentation,我做得对,但我的 scss 文件没有正确加载文件“变量”。这是我的 scss 文件的导入:

@import "variables";

这是发生的错误:

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

@import "variables";
^
      File to import not found or unreadable: variables.
      in /Users/erick/Projects/sample-project/src/styles.scss (line 2, column 1)

有什么建议可以在这里处理吗?

【问题讨论】:

    标签: angular sass angular-cli


    【解决方案1】:

    我找到了问题。

    我在angular.json 中加载themes/client-X 而不是src/themes/client-X

    【讨论】:

      【解决方案2】:

      我在运行测试时遇到了同样的问题,解决方法是在angular.json中的测试配置以及构建配置中添加相同样式的stylePreprocessorOptions

      【讨论】:

      • 我一直在寻找解决方案。我的产品包已成功编译。只是茉莉花测试失败了。按照你的方法为我解决了这个问题。谢谢西蒙斯
      猜你喜欢
      • 2019-03-25
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 2017-01-30
      • 2017-07-09
      • 1970-01-01
      相关资源
      最近更新 更多