感谢 Woot 的回答,这个答案更适合 .NET Core 2.0/2.1 开发人员通过以下方式使用 angular 种子项目:
#get lastest SPA templates and make sure angular CLI is global
dotnet new --install Microsoft.DotNet.Web.Spa.ProjectTemplates::*
npm install -g @angular/cli
#create a new project, default for target framework doesn't seem to be working when .NET Core 2.1 SDK is Installed
dotnet new angular -f netcoreapp2.0 -o test-web-app
此种子项目仍使用 bootstrap 3 版本,因此需要下载 bootstrap-sass(或升级到 bootstrap 4,其中包括基础节点模块中的 scss 支持):
npm install bootstrap-sass --save-dev
在 .angular-cli.json 文件中更改样式配置:
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
]
到:
"styles": [
"styles.scss",
"../node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss"
]
正如 Woot 所指出的,在自动创建文件时升级 angular cli 配置以创建 scss 文件而不是 css 文件也应该由以下人员执行:
ng set defaults.styleExt scss
并且需要将 styles.css 文件重命名为 styles.scss。
Angular CLI 和 Angular 版本在撰写本文时也略微过时(1.7.0 和 5.2.0),因此一旦升级,此答案可能会发生变化。 但就目前而言,这是可行的,不需要做任何其他事情来允许:
dotnet run
支持将 scss 自动编译为 css 并通过 ng serve 提供后台文件。