简体   繁体   English

从辅助条目导入 scss

[英]Import scss from a secondary entry

I have an Angular library which has secondary entries.我有一个 Angular 图书馆,其中有二级条目。 From one of those, I'd like to export a .scss file.从其中一个,我想导出一个.scss文件。

In my .tsconfig , I create a path:在我的.tsconfig中,我创建了一个路径:

...
path:{
 "@my-entry/*":["my-entry/*"]
}

And the entry filestructure:入口文件结构:

├── my-entry
    ├── index.ts
    ├── ng-package.json
    ├── src
        ├── index.ts
        ├── public_api.ts
        ├── */*.ts
        ├── my-styles.scss

In another entry, I'd like to use this scss file:在另一个条目中,我想use这个scss文件:

@use '@my-entry/src/my-styles.scss'

This obviously won't work, since I have only made a path for.ts, but I'd like to find a way to do something similar to tsconfig -> path for scss when making secondary entries.这显然是行不通的,因为我只为 .ts 创建了一个路径,但我想找到一种方法来做一些类似于tsconfig -> path for scss的事情,当创建辅助条目时。

Can this be done?这可以做到吗?

Thanks in advance.提前致谢。

There is an option called stylePreprocessorOptions for the angular workspace (Documentation found here ). angular 工作区有一个名为stylePreprocessorOptions的选项(在此处找到文档)。

Add your path to the build.options :将您的路径添加到build.options

// angular.json or project.json
"build": {
  "options": {
    ...
    "stylePreprocessorOptions": {
        "includePaths": ["my-entry/src"]
    },
    ...
  },
},

where my-entry/src is the path from the project root to the folder.其中my-entry/src是从项目根目录到文件夹的路径。 You can then import your file (and other files from that folder or subfolders)然后您可以导入您的文件(以及该文件夹或子文件夹中的其他文件)

// your .scss file
@import "my-styles";
@import "subfolder/theme";

Since this is an angular configuration your IDE might not know that import.由于这是一个 angular 配置,您的 IDE 可能不知道该导入。

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

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