如何缩小asp.net core中的文件? [英] How to minify files in asp.net core?

查看:71
本文介绍了如何缩小asp.net core中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

asp.net核心文档显示了操作方法使用grunt或gulp捆绑和缩小 css js 文件.但是,当我使用vs 2015创建项目时,它将 bundleconfig.json 文件添加到项目中.我想缩小wwwroot/js文件夹中的所有js文件.所以我更新了bundleconfig.json内部的现有行以使用通配符 *

Documentation for asp.net core shows how to do bundling and minification css and js files using grunt or gulp. However when i create a project using vs 2015 it adds bundleconfig.json file into project. I want to minify all the js files inside wwwroot/js folder. So i updated the existing lines inside bundleconfig.json to use wildcard character *

{
    "outputFileName": "wwwroot/js/*.min.js",
    "inputFiles": [
      "wwwroot/js/*.js"
    ],
    // Optionally specify minification options
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    // Optinally generate .map file
    "sourceMap": false
  }

但是,当我发布项目时却出现错误

however when i publish the project i get error

处理wwwroot/js/*.min.js路径中的非法字符.范围名称:路径

Processing wwwroot/js/*.min.js Illegal characters in path. Parameter name: path

推荐答案

我认为您不能在 outputFileName 中使用通配符,因此请在此处使用绝对路径.要创建多个捆绑包,请在阵列中创建多个条目.

I think you can't have wildcards in outputFileName, so use an absolute path here. To create multiple bundles create multiple entries in the array.

[
  {
    "outputFileName": "wwwroot/css/site.min.css",
    // An array of relative input file paths. Globbing patterns supported
    "inputFiles": [
      "wwwroot/css/site.css"
    ]
  },
  {
    "outputFileName": "wwwroot/js/site.min.js",
    "inputFiles": [
      "wwwroot/js/site.js"
    ],
    // Optionally specify minification options
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    // Optinally generate .map file
    "sourceMap": false
  }
]

以上内容来自默认的 bundleconfig.json .

旁注:

*.min.js 也是 *.js 顺便说一句.因此,如果您不删除前一个捆绑包,它将在每个捆绑包中递归添加,因此请小心.

*.min.js is also a *.js btw. So if you don't delete the previous one it will be added recursively with each bundling, so be careful.

这篇关于如何缩小asp.net core中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆