Home  >  Article  >  Web Front-end  >  How to Fix Bundler Excluding Minified Files in MVC4?

How to Fix Bundler Excluding Minified Files in MVC4?

Susan Sarandon
Susan SarandonOriginal
2024-10-19 14:53:30601browse

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>

Use:

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

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>

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!

Statement:
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