【问题标题】:How to use stylePreprocessorOptions in Angular8如何在 Angular8 中使用 stylePreprocessorOptions
【发布时间】:2020-06-30 09:58:58
【问题描述】:

我正在尝试学习如何在两个项目(project1,project2)中使用常见的 css 和 js。我已经在 angular.json 中的 stylePreprocessorOptions 下对其进行了谷歌搜索,如下所示

    "stylePreprocessorOptions": {
      "includePaths": [
        "styles"
      ]
    },

在图片中你可以找到我使用 check.css 的项目文件夹之外的文件夹

p{
  color:red
}

但它不会影响我的 P 标签如果我遗漏了什么请告诉我如何在多个项目中使用通用 css 和 js 文件。

【问题讨论】:

    标签: angular angular8


    【解决方案1】:

    希望这个答案对您有所帮助
    假设您有一个 style.css 包含所有 css 代码,并且您想将其导入到不同的组件中以使用其代码

        lets say import "./../../code/styles.css";  //This is not good to import all the time
        
        "stylePreprocessorOptions":{
        "includePaths":[
              "./code"
            ]
          }
    
    U can import simply like this
    
    import "styles";
    

    【讨论】:

    • ./src/styles.css 中的错误(C:/Users/harul/libraryCheck/node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw- css-loader.js!C:/Users/harul/libraryCheck/node_modules/postcss-loader/src??embedded!./src/styles.css) 模块构建失败(来自 C:/Users/harul/libraryCheck/node_modules/ postcss-loader/src/index.js):错误:无法在 C:\Users\harul\libraryCheck\node_modules\postcss- 的 [ C:\Users\harul\libraryCheck\projects\project1\src ] 中找到“检查” import\lib\resolve-id.js:35:13 at async Promise.all (index 0)
    • @import "检查";嗨,我已经像这样导入了
    猜你喜欢
    • 2020-01-30
    • 2019-03-29
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    相关资源
    最近更新 更多