是否可以使用类似于从同一工作区中的应用程序解析ts
个文件的方法来解析工作区库中包含的SA?对于上下文,我将设置一个真实的工作空间,如下所示:
ng new theme-workspace --create-application=false
cd theme-workspace
ng g library theme
mkdir projects/theme/src/lib/styles
touch projects/theme/src/lib/styles/index.scss
ng g application playground
在目录projects/theme/src/lib/styles
内,我们将向index.scss
添加以下内容.
$color: red;
为了包括样式资源,我们需要使用asset
块更新ng-package.json
,如下所示:
"assets": [
{ "input": "src/lib/styles", "glob": "**/*.scss", "output": "styles" }
]
如果我们像这样构建这个项目库:
ng build theme
我们看到dist/theme/styles
等于index.scss
.
我们可以像这样从操场访问生成的ts
组件ThemeComponent
.
import { ThemeComponent } from 'theme';
在使用@use
导入sass index.scss
模块时,是否可以使用类似的命名空间?
例如,如果我们try 从操场styles.scss
模块执行此操作,则会失败:
@use `theme/styles` as t;
这就是错误所在.
SassError: Can't find stylesheet to import.
╷
2 │ @use 'theme/styles' as t;
现在我们可以通过使用相对文件导入来解析,但我很好奇是否有一种使用库名称空间的"简写"方法?