How to manage ASP.NET Core bundleconfig.json for multiple environments?

前端 未结 3 1752
无人共我
无人共我 2021-01-02 11:41

What\'s the best practice for using the ASP.NET Core bundleconfig.json with development versus production environments? The prior bundler (BundleCollection) wou

3条回答
  •  佛祖请我去吃肉
    2021-01-02 12:15

    I wouldn't exactly call this a best practice but the following works for me.

    In the bundleconfig.json I prepare one bundle for development and one for production. Bundle for development is just concatenated text, which is easy to read and debug. Bundle for production is minified and may optionally include source map.

    {
        "outputFileName": "wwwroot/script.bundle.js",
        "inputFiles": [
          "wwwroot/node_modules/popper.js/dist/umd/popper.js",
          "wwwroot/node_modules/jquery/dist/jquery.js",
          "wwwroot/node_modules/bootstrap/dist/js/bootstrap.js"
        ],
        "minify": {
          "enabled": false,
          "renameLocals": false
        }
      },
      {
        "outputFileName": "wwwroot/script.min.js",
        "inputFiles": [
          "wwwroot/script.bundle.js"
        ],
        "minify": {
          "enabled": true,
          "renameLocals": true
        },
        // Optionally generate .map file
        "sourceMap": false
      }
    

    The point is, that production bundle use only development bundle. That way I have to keep only one list.

    On the page, where JS is needed, I add tags for two bundles.

    
        
    
    
        
    
    

提交回复
热议问题