0

As you probably know ASP.NET has an opportinity called Bundles and Minification. It allows to join scripts and styles to bundles and to minificate them. But if i want to use it i have to initialize my bundles from BundleConfig.cs and to register them from Application_Start. Can i do it in web.config or is it impossible?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
JuniorThree
  • 143
  • 7
  • 1
    No, that's not how MVC's bundling works. Explain why you want that. – CodeCaster Apr 15 '15 at 09:24
  • Ok, can you tell me why that's not how MVC's bundling works? – JuniorThree Apr 15 '15 at 09:32
  • 1
    No, that's pretty well documented on their site and it wouldn't help you any further. Explain why you want to "initialize bundling from config". – CodeCaster Apr 15 '15 at 09:32
  • I want it because declaration js-files in web.config allows me to change these files without rebuilding my web application – JuniorThree Apr 15 '15 at 10:08
  • Yes, so you want to alter a site that's running on a production server. You shouldn't want to do that. See my answer for a way to do that, and tell your boss that this is not how professional software development is done. – CodeCaster Apr 15 '15 at 10:09
  • @CodeCaster thank you for the answer. You write that "this is not how professional software development is done" Why? What's the wrong with this way? IMHO it is pretty flexible way to change scripts for running site – JuniorThree Apr 15 '15 at 10:32
  • See [Wiki: DTAP](http://en.wikipedia.org/wiki/Development,_testing,_acceptance_and_production). You don't edit files directly on the server, because that prevents source control (which provides auditing) and causes issues when you release a new version from your development machine that didn't have the changes made on the server. See also [Developing on a production server](http://programmers.stackexchange.com/questions/182282/developing-on-a-production-server) and [An introduction to version control](http://guides.beanstalkapp.com/version-control/intro-to-version-control.html). – CodeCaster Apr 15 '15 at 10:33
  • And another question: Can i select minification algorithm for my bundles? – JuniorThree Apr 15 '15 at 10:45

1 Answers1

1

You can't. You can only enable or disable bundling from config.

If you want this because you want to be able to alter files in production without having to open Visual Studio and without having to follow a proper release cycle (which you shouldn't), you can simply create bundles that include all files:

bundles.Add(new StyleBundle("~/bundles/css")
                .Include("~/Content/*.css"));

bundles.Add(new ScriptBundle("~/bundles/js")
                .Include("~/Scripts/*.js"));

Then you can add and remove files from those directories as you please.

See Include all files in a folder in a single bundle to also include subdirectories.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272