ASP.net Core 2.1:BundleMinifir错误,找不到文件

时间:2018-10-29 13:22:28

标签: asp.net node.js json razor

以下问题我也有同样的问题。

ASP.NET Core 2.0: static file (site.min.js) not found

我将npm的依赖项设置如下

{
  "version": "1.0.0",
  "name": "asp.net",
  "private": true,
  "devDependencies": {
    "bootstrap": "^4.0.0",
    "jquery": "^3.3.1",
    "popper.js": "1.12.9"
  }
}

我这样设置bundleconfig.json

[
  {
    "outputFileName": "wwwroot/vendor/css/vendor.css",
    "inputFiles": [
      "node_modules/bootstrap/dist/css/bootstrap.css"
    ],
    "minify": { "enabled": true }
  },
  {
    "outputFileName": "wwwroot/vendor/js/vendor.js",
    "inputFiles": [
      "node_modules/popper.js/dist/umd/popper.js",
      "node_modules/jquery/dist/jquery.js",
      "node_modules/bootstrap/dist/js/bootstrap.js"
    ],
    "minify": { "enabled": true }
  }
]

我已成功按照以下指南安装了Bundler&Minifier软件包。

.NET Core2.0 bundleconfig.json not working

我的捆绑文件(vendor.css和vendor.js)已成功生成。

然后我按如下方式在布局文件中引用了这些文件。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - WebApplication2</title>

    <environment include="Development">
        <link rel="stylesheet" href="~/vendor/js/vendor.js" />
        <link rel="stylesheet" href="~/css/site.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/vendor/js/vendor.js"  asp-append-version="true" />
        <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
    </environment>
</head>
<body>

    <div class="container body-content">
        @RenderBody()
    </div>

    <environment include="Development">
        <script src="~/vendor/js/vendor.js"  asp-append-version="true"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    </environment>
    <environment exclude="Development">
        <script src="~/vendor/js/vendor.js"  asp-append-version="true"></script>
        <script src="~/js/site.min.js" asp-append-version="true"></script>
    </environment>

    @RenderSection("Scripts", required: false)
</body>
</html> 

但是引导CSS样式未加载,并且jQuery代码不起作用。我没有收到404错误代码,一切似乎都已找到。无论如何,捆绑包文件不起作用。

有什么解决办法吗?先感谢您。

0 个答案:

没有答案