11

I am seeing a weird behavior with bundling in my ASP.Net MVC 5 project. My project works just fine when I explicitly declare all the files in my BundleConfig.cs file as follows:

bundles.Add(new ScriptBundle("~/bundles/app").Include(
                "~/app/app.js",
                "~/app/config.js",
                "~/app/dir1/file1.js",
                "~/app/dir1/subdir1/file2.js",
                .....

However, if I switch to use IncludeDirectory instead, the script paths during development (BundleTable.EnableOptimizations = false) are not complete. This is what I see:

bundles.Add(new ScriptBundle("~/bundles/app").Include(
                "~/app/app.js",
                "~/app/config.js")
                .IncludeDirectory("~/app/dir1", "*.js", true)

Chrome shows me a 404 when it is trying to get file2.js. The bundling system adds the following to my layout page:

<script src="/app/app.js"></script>
<script src="/app/config.js"></script>
<script src="/app/dir1/file1.js"></script>
<script src="/app/dir1/file2.js"></script>

The path to file2.js is wrong. It omits the subdir1 part of the path. Am I missing something here?

6
  • It omits the dir2 part of the path. Do you mean subdir1?
    – Curtis
    Mar 24, 2014 at 14:26
  • yes - sorry about that. fixed it.
    – mithun_daa
    Mar 24, 2014 at 14:27
  • That's strange behavior. The bundler shouldn't follow directories recursively, so if you include ~/app/dir1, it should only include files immediately in that directory. If it's also including files in subdirectories, while not actually including that subdirectory in the path, that's a new one on me. In general, your best practice here is to be explicit. If you want a file included, include that file explicitly. Things like IncludeDirectory are dangerous in my opinion. Mar 24, 2014 at 14:31
  • What I think you should see in the browser html source is something like <script src="/bundles/app?v=*randomdigitshere*"></script> are you running the site locally?
    – mortb
    Mar 24, 2014 at 14:33
  • Yeah, I assume the OP is running locally, as the bundler doesn't do anything but just include all the files in debug mode. Regardless, though, even in production, the OP might have just the one file, but the code from /app/dir1/subdir1/file2.js would be missing from that bundled file. It doesn't really affect the question or possible answers either way. Mar 24, 2014 at 14:36

1 Answer 1

13

This is a known issue w/ version 1.1.1. Upgrade the package (or downgrade to 1.1.0) and it should fix your problem.

Web Optimization path issue while in debug mode

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.