捆绑链接的JavaScript文件 [英] Bundling a linked JavaScript file

查看:125
本文介绍了捆绑链接的JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Visual Studio 2012和MVC4工作。我添加了一个链接文件(从另一个项目)到我的MVC4应用。这里是该文件的属性:

I'm working with Visual Studio 2012 and MVC4. I've added a linked file (from another project) to my MVC4 application. Here are the properties of the file:


  • 生成操作:内容

  • 复制到输出目录:不复制

下面是我包的例子:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.unobtrusive*","~/Scripts/jquery.validate*","~/Scripts/FolderA/*.js"));

有关测试,我还添加了一个空JavaScript文件(temp.js)到该文件夹​​。这不是一个链接文件。当检查网页的源文件显示,但链接的文件没有。任我不能直接导航到该文件。在包中的其他文件出现就好了。

For testing, I've also added an empty JavaScript file (temp.js) to that folder. This is not a linked file. When inspecting the source of the page this file appears but the linked file does not. I cannot navigate directly to this file either. The other files in the bundle appear just fine.

可以链接的文件捆绑在一起?

Can linked files be bundled?

推荐答案

简短的回答:没有在调试模式,是在释放模式

文件链接是用于别处包括存储到code和资源编译文件一个Visual Studio概念。显然,链接文件,如果你需要编译它(这是一个源文件)会的工作,如果你需要嵌入它作为一种资源,或者你需要它复制到目标目录(如果复制到输出目录设置为复印件)。

File linking is a Visual Studio concept used to include files stored elsewhere into code and resource compilation. Clearly, linking a file will work if you need to compile it (it's a source file), if you need to embed it as a resource or you need it copied to target directory (if Copy to Output Directory is set to Copy).

为什么不能在调试模式下工作

在调试模式,捆绑销售被禁止和脚本链接到个别。由于文件不会复制到Web应用程序根,他们不会通过IIS访问的用户。如果你试图让每一个构建应用程序的时间脚本文件的复制,文件将被复制到Web应用程序的目录。此目录无法访问通过IIS,并再次这是不行的。

In debug mode, bundling is disabled and scripts are linked to individually. Since files are not copied to root of your web application, they will not be accessible to user through IIS. If you try to enable copying of the script file every time you build the application, file will be copied to bin directory of web application. This directory is not accessible through IIS, and again this won't work.

为什么它的工作原理在释放模式

在释放模式,执行脚本的捆绑。脚本文件未链接到单独从网页,因此用户不需要直接对它们具有访问。只有捆绑code需要能够访问它。但是,你必须要偷偷摸摸有关配置此。您需要:

In release mode, bundling of scripts is performed. Script files are not linked to individually from web pages, and therefore user does not need to have access to them directly. Only bundling code needs to be able to access it. But you have to be sneaky about configuring this. You need to:


  • 设置复制到链接脚本的输出目录复制总是。如果您存储您的链接脚本在〜/脚本,一旦您编译应用程序,他们将被复制到〜/斌/脚本文件夹中。

  • 配置捆绑路径包括目录。

  • Set Copy to Output Directory of linked scripts to Copy always. If you store your linked scripts in ~/Scripts, once you compile the application they will be copied to ~/bin/Scripts folder.
  • Configure bundling path to include bin directory.

请注意〜/斌/脚本/ 在下面一行:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.unobtrusive*","~/Scripts/jquery.validate*","~/bin/Scripts/FolderA/*.js"));


禁用调试模式

调试模式没有编译器在Visual Studio设置。这是的web.config 文件中的元素。

Debug mode mentioned here is not compiler setting in Visual Studio. This is an element in web.config file.

<system.web>
    <compilation debug="false" targetFramework="4.5" />

这篇关于捆绑链接的JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆