Home > Web Front-end > JS Tutorial > body text

How to Fix Bundler Excluding Minified Files in MVC4?

Susan Sarandon
Release: 2024-10-19 14:53:30
Original
598 people have browsed it

How to Fix Bundler Excluding Minified Files in MVC4?

Bundler Excluding Minified Files

In MVC4, the bundling system sometimes encounters an issue where it excludes files with the ".min.js" extension. To resolve this, ensure that the bundle declaration includes ".js" extensions for minified files. For instance, instead of:

<code class="pre">.Include("~/Scripts/jquery-1.8.0.js")
.Include("~/Scripts/jquery.tmpl.min.js")</code>
Copy after login

Use:

<code class="pre">.Include("~/Scripts/jquery-1.8.0.js")
.Include("~/Scripts/jquery.tmpl.js")</code>
Copy after login

If renaming the files is not preferred, an alternative solution involves adding specific file patterns to the bundle's ignore list. This can be done by overriding the AddDefaultIgnorePatterns method in the BundleCollection class, as follows:

<code class="pre">public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
{
    // Existing ignore patterns
    // ...

    // Ignore additional file patterns
    ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
    ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
}

public static void RegisterBundles(BundleCollection bundles)
{
    // ...
}</code>
Copy after login

By overriding the AddDefaultIgnorePatterns method, you can specify that minified JavaScript and CSS files should be ignored when optimization is disabled in the deployment environment. This ensures that the bundler includes these files when serving the site in development or testing environments.

The above is the detailed content of How to Fix Bundler Excluding Minified Files in MVC4?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!