Javascript Bundling on visual studio 2015

后端 未结 5 1369
Happy的楠姐
Happy的楠姐 2021-02-14 06:01

System.Web.Optimization on Visual Studio 2013 was giving us Bundling on javascript files and the best part of that was allowing us to go with indiv

5条回答
  •  悲哀的现实
    2021-02-14 06:45

    After reading through the documentation and examples provided here, I immediately had the same question. After the bundling and minification steps, the docs just say "Now reference the files".

    I did quite a bit of research trying to find a best practice to use for conditionally referencing scripts for development and others for production. The options I like the most are:

    1. Use WireDep or gulp-inject to replace placeholder values in your view templates with dynamically defined file references. You can choose different files to include in your gulpfile based on environment and conditionally choose whether to bundle or not. This works great for local files, but isn't so great if you want to use a CDN.
    2. Use the environment tag helper to conditionally define file references. This option works great if you want to reference files from a CDN, and gives you the option to switch between local files for development and CDN files for production.

    Documentation for WireDep and gulp-inject are provided in their respective links.

    To use the environment tag helper, make sure your _GlobalImport view file has the following line in it.

    @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
    

    Then use it like this:

    
        
        
        
    
    
        
        
    
    

    The environment names correspond to the ASP.NET 5 environment variable ASPNET_ENV.

提交回复
热议问题