简体   繁体   English

Asp.net MVC 5将所有脚本捆绑在一个文件中

[英]Asp.net MVC 5 bundle all scripts in one file

In one of my razor page I have the following in the scripts section 在我的剃刀页面之一中,脚本部分具有以下内容

   @Scripts.Render("~/bundles/script1")
   @Scripts.Render("~/bundles/script2")
   @Scripts.Render("~/bundles/script3")

The problem is it will render 3 JavaScript files. 问题在于它将渲染3个JavaScript文件。 Is there any way they can be bundled in one file without changing the BundleConfig file? 有什么方法可以将它们捆绑在一个文件中而无需更改BundleConfig文件?

Thanks, 谢谢,

The problem is it will render 3 JavaScript files. 问题在于它将渲染3个JavaScript文件。 Is there any way they can be bundled in one file without changing the BundleConfig file? 有什么方法可以将它们捆绑在一个文件中而无需更改BundleConfig文件?

No, you will have to change your BundleConfig. 不,您将必须更改BundleConfig。

Well, if you want to reuse script1 in another page, how will you do that? 好吧,如果您想在另一个页面中重用script1,您将如何做?

Make a script bundle include another script bundle 使脚本包包括另一个脚本包

Yes you can create a Bundle containing all the files from Script1, 2 and 3 Bundles and then lets say if its called ScriptAll bundle then you can render it with 1 line. 是的,您可以创建一个包含Script1、2和3捆绑包中所有文件的捆绑包,然后说它是否名为ScriptAll捆绑包,则可以用1行渲染。 Unfortunately you will have to change your BundleConfig 不幸的是,您将不得不更改BundleConfig

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

why would You do this ? 你为什么要这样做 ? copy the code from these 3 files and paste it to one.js file then pass it to bundles. 复制这3个文件中的代码并将其粘贴到one.js文件中,然后将其传递给分发包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM