angular / angular/angular-cli

Workspace library scss import

未關閉
#23,552 9 則留言 19 個 reaction 已指派 0 人 在 GitHub 檢視
area: @schematics/angular freq1: low severity3: broken type: bug/fix
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
14 小時 23 分鐘
30 天內合併 PR
162

描述

# 🚀 Feature request

### Command (mark with an `x`)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [x] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] extract-i18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

### Description

With a workspace architecture, the exported stylesheets cannot be imported using package name. Given a library (`lib`) and a project (`app`) in an angular workspace. The library properly copies an scss file to the `dist` folder (which is the default output folder) and adds it to the `exports` section of the `package.json`. However, the consuming app cannot `@import` or `@use` the exported scss file.

Given the following files:

- dist/my-company/my-lib/assets/_theme.scss
- projects/app/src/styles.scss

And the following export in the `package.json` of the library:

```
"exports": {
"./theme": {
"sass": "./assets/_theme.scss"
}
},
```

And the default settings that the Angular CLI generates (with `ng new library` and so on...),

### Describe the solution you'd like

With the settings mentioned above, importing an exported scss file should work out of the box (currently it does not compile with the error `SassError: Can't find stylesheet to import.`).

```
// styles.scss
@use "@my-company/my-lib/theme" as myTheme;
```

### Describe alternatives you've considered

1. Changing the default `dist` output of the library to the `node_modules` and the automatically removed `@` symbol is added to the path (in short `dist/my-company/my-lib` -> `node_modules/@my-company/my-lib`) resolves the scss import problem. The `tsconfig.json` must be adjusted as well. If this is the desired solution, then it should be the default generated with the CLI.
2. Create an NPM Link to the dist directory (which has its own pros and cons). If this is the desired solution, then the `tsconfig.json` does not need to define additional `paths` and this should be an operation that the generation (through the CLI) does automatically. Or at least extend [the documentation](https://angular.io/guide/creating-libraries#managing-assets-in-a-library).

貢獻指南

開啟貢獻指南

研究方向

從 workspace 函式庫的 build 和 generate 路徑開始,以產生的 dist/my-company/my-lib/assets/_theme.scss、package.json 中的 exports 項目和 projects/app/src/styles.scss 作為重現點。執行應用程式的 @use 匯入並檢查產生的 tsconfig.json 設定;完成的標準是匯出的 SCSS 不需要手動路徑或 npm-link 變通方案即可解析。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
angular, scss, typescript
領域
build-system, cli, frontend
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。