My BundleConfig.cs
file looks like this (CSS):
我的BundleConfig.cs文件看起来像这样(CSS):
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/bootstrap-switch.css",
"~/Content/datepicker.css",
"~/Content/bootstrap-duallistbox.css",
"~/Content/fullcalender.css",
"~/Content/fullcalender.print.css"));
BundleTable.EnableOptimizations = true;
No where am I calling bootstrap.min.css, however, when I updated only the bootstrap.css file none of my changes were recognized. I started to make the changes in the .min file and then I noticed my changes.
我在哪里调用bootstrap.min.css,但是,当我只更新bootstrap.css文件时,我的所有更改都没有被识别。我开始在.min文件中进行更改,然后我注意到了我的更改。
I get that the BundleTable.EnableOptimizations = true;
takes all of the .css files and minimizes them, but I don't understand why I had to update the .min file for it to recognize my style changes.
我得到了BundleTable.EnableOptimizations = true;获取所有.css文件并最小化它们,但我不明白为什么我必须更新.min文件才能识别我的样式更改。
I expected the bootstrap.css
file to be minimized in memory and used that way.
我希望bootstrap.css文件在内存中最小化并以这种方式使用。
Can someone explain why this is occurring?
有人可以解释为什么会这样吗?
Just for more information I'm using MVC5 in VS2013
只是为了获得更多信息,我在VS2013中使用MVC5
1 个解决方案
#1
1
When you include stylesheet.css
in an bundle and there is already a stylesheet.min.css
file in your project, the optimization framework will use the .min
file when BundleTable.EnableOptimizations == true
.
当您在一个包中包含stylesheet.css并且项目中已经有一个stylesheet.min.css文件时,优化框架将在BundleTable.EnableOptimizations == true时使用.min文件。
It does the same thing for script.min.js
files.
它对script.min.js文件做了同样的事情。
BundleTable.EnableOptimizations = true; // when this is not false
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css", // will look for bootstrap.min.css
"~/Content/site.css", // will look for site.min.css
"~/Content/bootstrap-switch.css", // will look for bootstrap-switch.min.css
"~/Content/datepicker.css", // will look for datepicker.min.css
"~/Content/bootstrap-duallistbox.css", // will look for bootstrap-duallistbox.min.css
"~/Content/fullcalender.css", // will look for fullcalender.min.css
"~/Content/fullcalender.print.css")); // will look for fullcalender.print.min.css
If you would rather have the optimization framework minify for you, just remove bootstrap.min.css from your project.
如果您希望优化框架为您缩小,只需从项目中删除bootstrap.min.css即可。
来自文档:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
// Code removed for clarity.
}
The preceding code creates a new JavaScript bundle named ~/bundles/jquery that includes all the appropriate (that is debug or minified but not .vsdoc) files in the Scripts folder that match the wild card string "~/Scripts/jquery-{version}.js". For ASP.NET MVC 4, this means with a debug configuration, the file jquery-1.7.1.js will be added to the bundle. In a release configuration, jquery-1.7.1.min.js will be added. The bundling framework follows several common conventions such as:
上面的代码创建了一个名为〜/ bundles / jquery的新JavaScript包,其中包含Scripts文件夹中与通配符字符串“〜/ Scripts / jquery- {version”匹配的所有相应的(即调试或缩小但不是.vsdoc)文件} .js文件”。对于ASP.NET MVC 4,这意味着使用调试配置,文件jquery-1.7.1.js将添加到包中。在发布配置中,将添加jquery-1.7.1.min.js。捆绑框架遵循几个常见的约定,例如:
- Selecting “.min” file for release when “FileX.min.js” and “FileX.js” exist.
- 当存在“FileX.min.js”和“FileX.js”时,选择“.min”文件进行发布。
- Selecting the non “.min” version for debug.
- 选择非“.min”版本进行调试。
- Ignoring “-vsdoc” files (such as jquery-1.7.1-vsdoc.js), which are used only by IntelliSense.
- 忽略仅由IntelliSense使用的“-vsdoc”文件(例如jquery-1.7.1-vsdoc.js)。
#1
1
When you include stylesheet.css
in an bundle and there is already a stylesheet.min.css
file in your project, the optimization framework will use the .min
file when BundleTable.EnableOptimizations == true
.
当您在一个包中包含stylesheet.css并且项目中已经有一个stylesheet.min.css文件时,优化框架将在BundleTable.EnableOptimizations == true时使用.min文件。
It does the same thing for script.min.js
files.
它对script.min.js文件做了同样的事情。
BundleTable.EnableOptimizations = true; // when this is not false
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css", // will look for bootstrap.min.css
"~/Content/site.css", // will look for site.min.css
"~/Content/bootstrap-switch.css", // will look for bootstrap-switch.min.css
"~/Content/datepicker.css", // will look for datepicker.min.css
"~/Content/bootstrap-duallistbox.css", // will look for bootstrap-duallistbox.min.css
"~/Content/fullcalender.css", // will look for fullcalender.min.css
"~/Content/fullcalender.print.css")); // will look for fullcalender.print.min.css
If you would rather have the optimization framework minify for you, just remove bootstrap.min.css from your project.
如果您希望优化框架为您缩小,只需从项目中删除bootstrap.min.css即可。
来自文档:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
// Code removed for clarity.
}
The preceding code creates a new JavaScript bundle named ~/bundles/jquery that includes all the appropriate (that is debug or minified but not .vsdoc) files in the Scripts folder that match the wild card string "~/Scripts/jquery-{version}.js". For ASP.NET MVC 4, this means with a debug configuration, the file jquery-1.7.1.js will be added to the bundle. In a release configuration, jquery-1.7.1.min.js will be added. The bundling framework follows several common conventions such as:
上面的代码创建了一个名为〜/ bundles / jquery的新JavaScript包,其中包含Scripts文件夹中与通配符字符串“〜/ Scripts / jquery- {version”匹配的所有相应的(即调试或缩小但不是.vsdoc)文件} .js文件”。对于ASP.NET MVC 4,这意味着使用调试配置,文件jquery-1.7.1.js将添加到包中。在发布配置中,将添加jquery-1.7.1.min.js。捆绑框架遵循几个常见的约定,例如:
- Selecting “.min” file for release when “FileX.min.js” and “FileX.js” exist.
- 当存在“FileX.min.js”和“FileX.js”时,选择“.min”文件进行发布。
- Selecting the non “.min” version for debug.
- 选择非“.min”版本进行调试。
- Ignoring “-vsdoc” files (such as jquery-1.7.1-vsdoc.js), which are used only by IntelliSense.
- 忽略仅由IntelliSense使用的“-vsdoc”文件(例如jquery-1.7.1-vsdoc.js)。