angular - ASP.NET Core Angular 模板 - 在 ng build --prod 之后不会应用组件样式
问题描述
重现步骤:
- 使用 .NET Core SDK 3.1 (Visual Studio 2019) 创建新的 ASP.NET Core Angular 应用程序
- 将新的 CSS 文件 (home.component.css) 添加到主组件
- 更新 home.component.ts 以包含新添加的 CSS 文件
.acs-h1 {
color: blueviolet
}
<h1 class="acs-h1">Hello, world!</h1>
<p>Welcome to your new single-page application, built with:</p>
<ul>
<li><a href='https://get.asp.net/'>ASP.NET Core</a> and <a href='https://msdn.microsoft.com/en-us/library/67ef8sbd.aspx'>C#</a> for cross-platform server-side code</li>
<li><a href='https://angular.io/'>Angular</a> and <a href='http://www.typescriptlang.org/'>TypeScript</a> for client-side code</li>
<li><a href='http://getbootstrap.com/'>Bootstrap</a> for layout and styling</li>
</ul>
<p>To help you get started, we've also set up:</p>
<ul>
<li><strong>Client-side navigation</strong>. For example, click <em>Counter</em> then <em>Back</em> to return here.</li>
<li><strong>Angular CLI integration</strong>. In development mode, there's no need to run <code>ng serve</code>. It runs in the background automatically, so your client-side resources are dynamically built on demand and the page refreshes when you modify
any file.</li>
<li><strong>Efficient production builds</strong>. In production mode, development-time features are disabled, and your <code>dotnet publish</code> configuration automatically invokes <code>ng build</code> to produce minified, ahead-of-time compiled JavaScript
files.</li>
</ul>
<p>The <code>ClientApp</code> subdirectory is a standard Angular CLI application. If yo**strong text**u open a command prompt in that directory, you can run any <code>ng</code> command (e.g., <code>ng test</code>), or use <code>npm</code> to install extra packages into
it.</p>
- 在本地运行应用程序,应用来自 home.component.css 的样式
- 发布和部署应用程序,来自 home.component.css 的样式不适用,此外 nav-menu.component.css 中的任何默认样式都不会应用到已部署的包中
我对 .NET Core SDK 3.0 进行了同样的尝试并得到了相同的结果。
还注意到默认的 ASP.NET Core Angular 模板<body>
在 index.html 和 app.component.html 中都有一个标签。我尝试从 app.component.html 中删除它,但没有帮助。
解决方案
推荐阅读
- ios - 如何在 UITabBarController 中获取特定 UIViewController 的索引
- rest - 如何设计用于报告仪表板的rest api?在服务器端创建报表所需的所有数据或在 UI 中操作数据?
- apache-spark - Pyspark:如何在一行中获得今天的分数和 30 天的平均分数
- javascript - nodejs cloudflare ERR_CERT_AUTHORITY_INVALID
- prolog - Prolog中美元符号($)和数字(或哈希)符号(#)的区别
- python - 导入 scipy.stats 时,得到“ImportError: DLL load failed: The specified procedure could not be found”
- c# - UWP Vs 中 ITextRange 接口的使用。WPF 中的 TextRange 对象
- raku - 在Perl6中逐行读取文件,如何惯用?
- java - 为什么 AlarmClock.EXTRA_SKIP_UI 不能与 AlarmClock.ACTION_DISMISS_ALARM 一起使用?
- android - 如何制作自定义TextView - 如何将单词的每个字母放在正方形内