具有虚拟目录的WebForms中的脚本捆绑 [英] Script Bundling in WebForms with Virtual Directories
问题描述
我们有一个单独的框架"项目,用于该项目和其他项目所使用的共享控件,javascript等. Framework项目包含在我们的解决方案中,并且我们使用IIS为它创建了一个虚拟目录,因此我们仍然可以使用~/Framework
建立相对于文件的相对链接.
We have a separate "Framework" project for shared controls, javascript, etc. that is used by this and other projects. The Framework project is included in our solution, and we made a virtual directory for it with IIS so we can still make relative links to files with ~/Framework
.
因此,我们要开始使用针对脚本和样式的新的Web Optimization捆绑包.一切工作正常,但是尝试将捆绑与虚拟目录中的JS文件一起使用时遇到问题.设置debug="false"
时,文件已正确捆绑& ;;缩小.设置debug="true"
时,它不包含文件的 any !
So, we want to begin using the new Web Optimization bundles for scripts and styles. Everything is working fine, but we are having issues when attempting to use bundling with JS files in the virtual directory. When debug="false"
is set, the files are correctly bundled & minified. When debug="true"
is set it does not include any of the files!
很显然,它可以捆绑& ;;,因此可以访问文件.一起缩小它们.有办法使这项工作吗?
Clearly it has access to the files since it can bundle & minify them together. Is there a way to make this work?
这就是我在App_Start/BundleConfig.vb
Public Shared Sub RegisterBundles(bundles As BundleCollection)
Dim mainBundle = New ScriptBundle("~/bundles/main")
mainBundle.Orderer = New AsIsBundleOrderer()
mainBundle.Include("~/Framework/Javascript/Main/Library.jQuery.js")
mainBundle.Include("~/Framework/Javascript/Main/Library.jQuery.ui.js")
'snip....
mainBundle.Include("~/Framework/Javascript/Main/CP.Base.js")
bundles.Add(mainBundle)
End Sub
这是我的母版页中的内容:
Here's what I have in my MasterPage:
<%: System.Web.Optimization.Scripts.Render("~/bundles/main") %>
推荐答案
在项目的 App_Code 文件夹下创建一个类,并将此代码添加到该类中
create a class under App_Code folder in your project and add this code in to the class
Public Shared Sub RegisterBundles(bundles As BundleCollection)
Dim mainBundle = New ScriptBundle("~/bundles/main")
mainBundle.Orderer = New DefaultBundleOrderer()
mainBundle.Include("~/HTML5Components/adc.js")
bundles.Add(mainBundle)
End Sub
之后,打开 Global.asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
BundleConfig.RegisterBundles(BundleTable.Bundles)
End Sub
这篇关于具有虚拟目录的WebForms中的脚本捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!