Buscar contenidos

jueves, 27 de septiembre de 2018

NetCore, JS, CSS Bundling


Options for CSS and JS Bundling and Minification with ASP.NET Core

https://stackoverflow.com/questions/48415335/how-can-i-use-scrips-render-with-net-core-2-0-mvc-application
In ASP.Net MVC Core they removed BundleConfig.cs and replaced with bundleconfig.json file. you need to specify your bundle and minification logic in bundleconfig.json. If you don't have this file in your project add json file with this name.
bundleconfig.json
Content of this file should like below.
  // Configure bundling and minification for the project.
// More info at https://go.microsoft.com/fwlink/?LinkId=808241
[
  {
    "outputFileName": "wwwroot/css/site.min.css",
    // An array of relative input file paths. Globbing patterns supported
    "inputFiles": [
      "wwwroot/css/site.css"
    ]
  },
  {
    "outputFileName": "wwwroot/js/bundles.min.js",
    "inputFiles": [
      "wwwroot/js/site.js",
      "wwwroot/lib/jquery/dist/jquery.js",
      "wwwroot/lib/jquery/dist/jqueryvalidate.js"
    ],
    // Optionally specify minification options
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    // Optionally generate .map file
    "sourceMap": false
  }
]
_Layout.cshtml
 <script src="~/js/bundles.min.js"></script>
Read Microsoft docs related to Bundling and minification to get more understanding about Bundling and minification in asp.net core mvc

No hay comentarios:

Publicar un comentario