Bundle.config困惑调试和发布,并缩小 [英] Bundle.config confused about debug and release and minification

查看:1875
本文介绍了Bundle.config困惑调试和发布,并缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读这篇文章<一个href=\"http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification\">http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification我只是觉得有很多内容,从它丢失了。

I read this article http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification and I just feel there's a lot of content missing from it.

我是开发使用unminified JavaScript文件的项目。然而,这成为一个问题,当我决定把我的项目发布到另一台服务器,其中bundle.config劫持我的javascript文件和做的事情我从来不知道我需要测试我的发展,现在我的开发机是投掷各种JavaScript错误。所以,现在我在这里,什么bundle.config与分档不读了。

I was developing on a project using unminified javascript files. However, this became an issue when I decided to publish my project to another server, where bundle.config hijacks my javascript files and does things I never knew that I needed to test on my development, and now my dev machine is throwing all kinds of javascript errors. So now, I'm here, reading up on what bundle.config does with min files.

阅读文章后,我做了如下假设:

After reading the article, I made the following assumptions:

如果我把我的项目调试模式下,我的项目将获得不包含任何min.js文件中的所有JavaScript文件。

If I set my project to debug mode, my project will get all javascript files that does not contain any "min.js" files.

如果我把我的项目为发布模式,我的项目将尝试让我的所有min.js文件,如果没有min.js文件,那么非最小文件将被转换为缩小的版本。

if I set my project to release mode, my project will attempt to get all my min.js files, and if there are no min.js files, then the non-min files will be converted to a minified version.

,原来我的错误即可。切换到发布模式并没有对分档什么,它的行为方式与我的调试模式相同。

Based on those two assumptions, turns out I was wrong. Switching to Release mode doesn't do anything with min files, it acts the same way as my Debug mode.

其次,进入在web.config并设置以下为false(previously真):

Secondly, going into the web.config and setting the following to false (previously true):

<compilation debug="false" /> 

把我的所有文件未精缩和minifies他们,忽略任何分钟的文件我也有!我没有看到任何File.min.js,我看到的是一样的东西:文件V = DW-fikdksdm ......这是很好的,因为这被认为是捆绑,并得到缩小的,但为什么我不能只是看到我装分钟?如果缩小和捆绑抛出JavaScript错误会发生什么?什么会我在这一点上做的?我可以prevent从没有一些JavaScript文件包含在捆绑和/或缩小的?

takes all my files that are not minified and minifies them, ignoring any min files I have! I don't see anything about File.min.js, all I see is something like: "File?v=dw-fikdksdm..." which is fine, since this is considered a "bundle" and gets minified, but why can't I just see my mins loaded? and what happens if minification and bundling throws javascript errors? What would I have to do at this point? Can I prevent some javascript files from not being included in a bundle and/or minified?

另外我注意到有当试图加载了JavaScript资源发生一对夫妇403错误的。

Also I've noticed there are a couple of 403 errors that occur when tried to load up the javascript resources.

有人能解释一下是怎么回事,为什么这是违背了我原来的设想?

Can someone explain what's going on here and why this is goes against my original assumption?

推荐答案

好吧,这里有几件事情,我发现这一点:

Okay, here are a few things I discovered about this:

当在调试模式下,你检查web.config:

When in debug mode, and you check the web.config:

 <system.web>
     <compilation debug="true">

然后所有的JavaScript将是捆绑虚拟目录中pserved $ P $(他们不会合并成一个单一的文件,他们将不可以进行精缩)。

当切换到发布模式,然后切换到:

When switching to release mode, then switch to:

 <system.web>
     <compilation debug="false">

这样一个包内所有的JavaScript文件都精缩并编译成一个单一的文件,这样可以减少往返网络。请注意,一个文件为每个包创建的。

so that all your javascript files within a bundle are minified and compiled into a single file, this reduces round trips to the network. Please note, one file is created for each bundle.

如果你想获得的优化启用,无论你是否是没有在调试模式下,则设置BundleTable.EnableOptimizations = true,这迫使缩小和捆绑。如果你离开了这一点,在code,那么BundleConfig会看web.config文件来代替。

If you want to get the optimizations enabled regardless of whether or not you're in debug mode, then set BundleTable.EnableOptimizations = true, which forces the minification and bundling. If you leave this out of the code, then BundleConfig will look at the web.config instead.

RegisterBundles(BundleCollection bundles) method in BundleConfig.cs, you put in:

    BundleTable.EnableOptimizations = true;
    bundles.UseCdn = true;
    var cssTransformer = new CssTransformer();
    var jsTransformer = new JsTransformer();
    var nullOrderer = new NullOrderer();

这就是你如何在JavaScript文件添加:

and this is how you'd add in javascript files:

    var jqueryBundle = new CustomScriptBundle("~/bundles/jquery");
    jqueryBundle.IncludeDirectory("~/Scripts/JQuery", "*.js");
    jqueryBundle.Transforms.Add(jsTransformer);
    jqueryBundle.Orderer = nullOrderer;
    bundles.Add(jqueryBundle);

夫妻笔记:


  • Bundle.config确实忽略所有分文件。我加File.min.js和File.js,而忽略File.min.js,它minifies File.js并包含在捆绑其它文件捆绑它。我检查了,因为当我精缩的文件中的一个我自己,所有的相比,现在在我的网站上下载的变量名(不是结构化code)比最小的文件I包含在项目中完全不同。所以,这验证不需要在你的项目分文件。

  • Bundle.config忽略污染减量命名为这样的文件。File.debug.js,这将永远不会缩小的,其实,它永远不会被包含在发布你的项目。我意识到我的JavaScript文件的一个人永远做它该网站后,发现了这一点。

  • 403错误,如果你使用内容/ CSS为您的包就会出现在您的虚拟目录会发生,这需要改为包/ CSS和403将消失,像这样(用剃刀):

  • Bundle.config does ignore all min files. I added File.min.js, and File.js, and it ignores File.min.js, and it minifies File.js and bundles it with other files included in the bundle. I checked because when I minified one of the files myself, all the variable names (not the structured code) compared to what was downloaded in my website was completely different than the min file I included in the project. So, this verifies that min files are not needed in your project.
  • Bundle.config ignores minifying any files named like this.. "File.debug.js", this will never be minified, in fact, it will never be included in your project in release. I found this out after realizing one of my javascript files never making it to the site.
  • 403 errors will occur if you use "Content/css" as your virtual directory of where your bundle will appear, this needs to be changed to "bundles/css" and the 403 will go away like so (using razor):

@ Styles.Render(〜/包/ CSS)

@Styles.Render("~/bundles/css")

这意味着,如果你有这样的在code(通知其中〜/包/ CSS的是,这将是您的css文件会):

meaning if you have this in your code (notice where ~/bundle/css" is, this will be where your css files will go):

BundleTable.EnableOptimizations = true;

bundles.UseCdn = true;
var cssTransformer = new CssTransformer();
var jsTransformer = new JsTransformer();
var nullOrderer = new NullOrderer();
#region CSS Styles
var cssBundle = new CustomStyleBundle("~/bundles/css");
cssBundle.IncludeDirectory("~/Content/CSS", "*.css")
         .IncludeDirectory("~/Content/CSS/Override", "*.css");
cssBundle.Transforms.Add(cssTransformer);
cssBundle.Orderer = nullOrderer;
bundles.Add(cssBundle);
#endregion


  • 如果你的CSS有一个相对路径,这也可能会改变,因此寻找404错误

  • 不是所有的缩小的文件将行为方式,你希望他们..所以你将不得不最终做一个半捆绑版本(或者你没有来缩小任何JS可言,只是他们捆绑)

  • 但是,如果你想继续做的精缩的JavaScript,你不知道哪些文件被引发错误,下面的步骤将帮助:

    But if you want to continue on doing the minified javascript and you do not know which files is throwing the error, the following steps will help:


    1. 捆绑一切

    2. 打开浏览器,并找到自己的精缩捆绑JS的所有源

    3. 工作捆绑JS复制到另一个文件

    4. 开始使用标签而不是bundleconfig.cs手动插入JavaScript和不断增加逐一直到一个失败..如果失败..然后你就必须使用该项目的未精缩版

    5. 重复步骤3-4

    我希望有在写这篇文章的时候bundle.config的更好的文档,但我发现这整个体验受到严重失望。

    I wish there was better documentation of bundle.config at the time of this writing, but I found this entire experience to be severely disappointing.

    这篇关于Bundle.config困惑调试和发布,并缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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