【问题标题】:Add conditional css to bundleconfig将条件 css 添加到 bundleconfig
【发布时间】:2017-12-12 13:17:24
【问题描述】:

我有 2 个 css 文件。他们两个都是针对所有页面,除了其中一个是左边语言的修复,它将存在于选择左侧文化的权利时,并且否则不会在其中一部分。

布局文件中的当前定义:

<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
  }

有什么方法可以在需要时将其包含在捆绑中?我不想单独包含它。

【问题讨论】:

    标签: html css asp.net-mvc asp.net-core bundling-and-minification


    【解决方案1】:

    我解决了这个问题。

    在 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-12
      • 2011-10-15
      • 2013-09-08
      • 2018-07-21
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多