angular / angular/angular-cli

Workspace library scss import

Đang mở
#23,552 9 bình luận 19 reaction 0 người được giao Xem trên GitHub
area: @schematics/angular freq1: low severity3: broken type: bug/fix
Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
14 giờ 23 phút
Pull request đã merge (30 ngày)
162

Mô tả

# 🚀 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).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với các đường dẫn build và generate cho một thư viện workspace, sử dụng dist/my-company/my-lib/assets/_theme.scss được tạo, mục exports trong package.json và projects/app/src/styles.scss làm các điểm tái hiện. Chạy import @use của app và kiểm tra các thiết lập trong tsconfig.json được tạo; được xem là hoàn thành khi SCSS đã export được resolve mà không cần các workaround thủ công về đường dẫn hoặc npm-link.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, scss, typescript
Lĩnh vực
build-system, cli, frontend
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.