简体   繁体   English

在 Angular 库模块中导入 SCSS 变量文件

[英]Import SCSS variables file in Angular library modules

I am working on a project which is an Angular Library (which uses SCSS).我正在开发一个项目,它是一个 Angular 库(使用 SCSS)。

My project structure is like this:我的项目结构是这样的:

├───UI-lib
│   ├──assets
│   │   └───styles/
│   │         └───_theme.scss
│   │         └───_varialbes.scss
│   └──src
│       └───lib
│           └─modules
│              ├───autocomplete
│              │   └───components
│              │       └───auto-complete/
│              ├───checkbox
│              │   └───components
│              │       └───checkbox/

  ......................

 │       
 ├───App Test        
 ├───e2e/
 └───src
     ├───app         
          └───my-module

My ng-package.json :我的ng-package.json

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/ui-lib",
  "assets": [
    "./assets/"
  ],
  "lib": {
    "entryFile": "src/public-api.ts",
    "styleIncludePaths": [
      "./assets/styles/_theme.scss"
    ]
  },
  "whitelistedNonPeerDependencies": ["."]
}

The problem is that I am not able to import my _varialbe.scss file in my modules' components.问题是我无法在我的模块组件中导入我的_varialbe.scss文件。

Can you help me how can I import _variables.scss file in UI-lib/src/lib/modules/autcomplete/components/autocomplete/autocomplete.component.scss ?你能帮我如何在UI-lib/src/lib/modules/autcomplete/components/autocomplete/autocomplete.component.scss导入_variables.scss文件吗?

I tried to search online but didn't find the solution that works.我试图在线搜索,但没有找到有效的解决方案。

I have tried to import from the root folder of the project and it worked!!!我尝试从项目的根文件夹导入,并且成功了!!!

autocomplete.component.scss autocomplete.component.scss

@import "projects/ui-lib/assets/styles/_variables";
   
...

Importing node module scss files in simple, it can be imported using import in the scss file.导入节点模块scss文件很简单,可以在scss文件中使用import导入 For more details, you can look at this link有关更多详细信息,您可以查看此链接

Having scss files in assets folder is strange.在 assets 文件夹中有 scss 文件很奇怪。 Are you going to serve them as static resources?您打算将它们作为静态资源提供服务吗?

Any way, just use relative path (with a couple of ../ ) or an absolute path to your _variables.scss in order to import it.无论如何,只需使用相对路径(带有几个../ )或 _variables.scss 的绝对路径即可导入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM