无法从节点模块使用 SASS mixin 构建 Angular 库

pfe*_*eon 8 sass angular ng-packagr

设置:带有库的 Angular 9 工作区、一个使用 CDK 的测试应用程序和故事书_overlay.scss.scss文件中包含@use.

.storybook/
node_modules/
projects/
- library/
  - src/
    - lib/
      - component/
        component.scss // `@use`s `_overlay.scss`
  ng-package.json
- test-app/
angular.json
Run Code Online (Sandbox Code Playgroud)

问题:@use "~@angular/cdk/overlay"在测试应用程序和故事书编译中使用覆盖 sass 混合但 ng-packagr 找不到_overlay.scss.

ERROR: Can't find stylesheet to import.
  ?
2 ? @use "~@angular/cdk/overlay";
  ? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ?
  projects\library\src\lib\component\component.scss 2:1  root stylesheet
An unhandled exception occurred: Can't find stylesheet to import.
Run Code Online (Sandbox Code Playgroud)

解决方法:

  • 可以添加node_modules/tong-package.json"styleIncludePaths": "["../../node_modules"]"数组并像这样导入覆盖混合,@use "@angular/cdk/overlay"但它不适用于测试应用程序或故事书;此外,IDE 无法解析路径。
  • @use "overlay""styleIncludePaths": ["../../node_modules/@angular/cdk"]以及"stylePreprocessorOptions": {"includePaths": ["node_modules/@angular/cdk"]}作品的测试程序和库构建而不是故事书; 此外,IDE 无法解析路径。也许可以将故事书配置为使用此设置。
  • @use "../../../../../node_modules/@angular/cdk/overlay"在开发期间更改工作路径,但在有人尝试将库添加到他们的 node_modules 和@usemixin时会在生产中失败。
  • 复制_overlay.scss到库中是可行的,但每次 cdk 更改时都需要更新。
  • 提供自定义 webpack.config 可能会起作用,但如果引擎盖下的角度发生变化,则需要对其进行更新。

问:如果在中设置,使用波浪号导入~实际上不应该工作吗?这是 ng-packagr 的问题吗?"styleIncludePaths": ["../../node_modules/"]ng-package.json