css - 如何从 .NET Core 中的主视图和单个视图捆绑 CSS?
问题描述
我在项目中有以下内容。
_Layout.cshtml - Master page
<environment names="Development">
<link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment names="Staging,Production">
<link rel="stylesheet" href="~/css/site.min.css" />
</environment>
Page1.cshtml - uses Master page
<environment names="Development">
<link type="text/css" rel="stylesheet" href="~/css/page1.css">
</environment>
<environment names="Staging,Production">
<link type="text/css" rel="stylesheet" href="~/css/page1.min.css">
</environment>
About.cshtml - uses Master page
<!-- no styles specific to the page -->
我正在尝试创建一个捆绑包以将 css 作为单个文件提供服务。所以在 bundleconfig.json 我有以下内容:
{
"outputFileName": "wwwroot/css/site.min.css",
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/css/page1.bundled.min.css",
"inputFiles": [
"wwwroot/css/site.css",
"wwwroot/css/page1.css"
]
}
因此,当我服务器 Page1.cshtml 时,我将样式声明更改为以下内容:
<environment names="Staging,Production">
<link type="text/css" rel="stylesheet" href="~/css/page1.bundled.min.css">
</environment>
而 About.cshtml 仅依赖于母版页中的单个 site.min.css 文件。
但是,在这种情况下,Page1.cshtml 最终会同时提供 site.min.css(来自母版页)和 page1.bundled.min.css(已经包含 site.css)。这显然是错误的。
那么从主页面和单个页面捆绑文件的正确方法是什么?我是否从母版页中提取所有样式并直接从各个视图中提供特定于页面的捆绑包?这有点违背了拥有母版页的目的。
PS我之前问过这个问题,但我没有正确解释这个问题。
解决方案
推荐阅读
- bootstrap-4 - IE 11 中的 Blazor(服务器端)侧边栏兼容性问题
- python - 在python中使用字母顺序和整数对列表进行排序
- python - 将整个包添加到 Pyinstaller 可执行文件中
- java - 为 Cucumber Selenium 项目创建可执行 jar 文件
- html - 当我尝试在 Angular 7 的屏幕上执行任何操作时,HTML 表单被挂起/冻结
- react-native - 如何在 React Native 的 View 组件中应用两种不同的样式
- php - 目录更改时插件更新错误wordpress
- python - 通过范围索引获取整个数组
- python - 在 python 中可视化嵌套函数调用
- java - android studio switch 如何以编程方式设置开关的状态