ASP.NET Core MVC配置前端

ASP.NET Core MVC 分前后端:


• 后端一般用 NuGet
• 前端一般用 NPM


前端工具


• NPM:pacakage.json
• Bundle 和 minify:bundleconfig.json
• BuildBundlerMinifer
• Task Runners:Webpack,Gulp,Grunt


Bundle&minify
在前端项目中创建 bundleconfig.json 文件。


然后

[
  // 将 bootstrap.css 和 site.css 打包并压缩为 all.min.css ——————生产环境
  {
    "outputFileName": "wwwroot/css/all.min.css",
    "inputFiles": [
      "node_modules/bootstrap/dist/css/bootstrap.css",
      "wwwroot/css/site.css"
    ]
  },
  // 未压缩,相当于做了个复制操作 ----------------------------开发环境
  {
    "outputFileName": "wwwroot/css/bootstrap.css",
    "inputFiles": [
      "node_modules/bootstrap/dist/css/bootstrap.css"
    ],
    "minify": {
      "enabled": false
    }
  }
]

配置完后,再参考 Doc,从 NuGet 安装 BuildBundlerMinifier 插件。
安装好插件后,build 项目时会自动 bundle&minify

The BuildBundlerMinifier NuGet package enables the execution of bundling and minification at build time.
The package injects MSBuild Targets which run at build and clean time.
The bundleconfig.json file is analyzed by the build process to produce the output files based on the defined configuration.

posted @ 2020-10-24 13:54  李花花小番茄  阅读(514)  评论(0编辑  收藏  举报