asp.net - 在 MVC View 中添加具有散列名称的 js 文件(由 Angular CLI 生成)

标签 asp.net asp.net-mvc

我有一个 Angular 应用程序,使用集成在 MVC 项目中的 Angular CLI 构建。

我正在使用 ng build --prod --output-hashing none。输出文件被复制到 MVC 项目的一个文件夹中。由于文件名始终相同,我只是在 cshtml 中引用它们以加载角度应用程序。

...
<script type="text/javascript" src=".../inline.bundle.js"></script>
<script type="text/javascript" src=".../vendor.bundle.js"></script>
<script type="text/javascript" src=".../script.bundle.js"></script>
...

但是如果我使用 ng build --prod,这种方法就不起作用了,因为生成的文件的名称中有哈希值:inline.318b50c57b4eba3d437b.bundle.js

如何在 View 中包含这些文件

最佳答案

继续使用 --output-hashing none 并创建一个 ScriptBundleAppStart/BundleConfig.cs 中,它将添加相同的功能,并在 bundle-name 中添加哈希值。

BundleConfig.cs:

            bundles.Add(new ScriptBundle("~/bundles/app").Include(
                "~/Scripts/app/runtime.js",
                "~/Scripts/app/polyfills.js",
                "~/Scripts/app/scripts.js",
                "~/Scripts/app/vendor.js",
                "~/Scripts/app/main.js"

                //you might want the styles.js here as well for DEBUG-only - I left them out of this example
            ));
#if DEBUG
#else
            BundleTable.EnableOptimizations = true;
#endif

索引.cshtml:

    @Scripts.Render("~/bundles/app")

关于asp.net - 在 MVC View 中添加具有散列名称的 js 文件(由 Angular CLI 生成),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49345822/

相关文章:

jQuery 使用 ID 创建新的 div?

asp.net-mvc - CustomErrors on不适用于生产环境

c# - MVC Paypal 集成

.net - 无法加载DLL 'iclit09b.dll'

javascript - Knockout.js:如何对表进行排序?

asp.net - 如何管理每个选项卡一个 session ?

javascript - 修改Kendo UI Dropdownlist的change事件

asp.net - "Release"模式下的自定义错误页面和 "Debug"模式下的默认错误页面

ASP.NET MVC "Components"

asp.net - 获取在asp.net Identity 2.0中分配角色的用户列表