将条件 css 添加到 bundleconfig
Add conditional css to bundleconfig
我有 2 个 css 文件。它们俩都适用于所有页面,除了其中一个是修复右至左语言的修复,并且在选择右文化的所有页面中都存在于所有页面中,否则将在其中none中存在。
布局文件中的当前定义:
<environment names="Development">
<link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment names="Staging,Production">
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
bundleconfig.json:
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
有什么办法可以在需要的时候打包进来吗?我不想单独包含它。
我解决了问题。
在 bundleconfig.json 中,我选择创建 2 个不同的缩小版 css,一个有 rtl 补丁,一个没有:
[
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/css/sitertl.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css",
"wwwroot/css/rtl.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
]
在布局中我添加了这样的条件:
<environment names="Development">
<link rel="stylesheet" href="~/css/site.css" />
@if (CultureInfo.CurrentUICulture.Name.ToLower() == "fa-ir")
{ <link href="~/css/rtl.css" rel="stylesheet" />}
</environment>
<environment names="Staging,Production">
@if(CultureInfo.CurrentUICulture.Name.ToLower()=="fa-ir"){
<link rel="stylesheet" href="~/css/sitertl.min.css" asp-append-version="true" />}
else{
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
}
</environment>
我有 2 个 css 文件。它们俩都适用于所有页面,除了其中一个是修复右至左语言的修复,并且在选择右文化的所有页面中都存在于所有页面中,否则将在其中none中存在。
布局文件中的当前定义:
<environment names="Development">
<link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment names="Staging,Production">
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
bundleconfig.json:
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
有什么办法可以在需要的时候打包进来吗?我不想单独包含它。
我解决了问题。
在 bundleconfig.json 中,我选择创建 2 个不同的缩小版 css,一个有 rtl 补丁,一个没有:
[
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/css/sitertl.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css",
"wwwroot/css/rtl.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
]
在布局中我添加了这样的条件:
<environment names="Development">
<link rel="stylesheet" href="~/css/site.css" />
@if (CultureInfo.CurrentUICulture.Name.ToLower() == "fa-ir")
{ <link href="~/css/rtl.css" rel="stylesheet" />}
</environment>
<environment names="Staging,Production">
@if(CultureInfo.CurrentUICulture.Name.ToLower()=="fa-ir"){
<link rel="stylesheet" href="~/css/sitertl.min.css" asp-append-version="true" />}
else{
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
}
</environment>