简体   繁体   English

带有 Grunt Uglify 的动态文件名

[英]Dynamic Filename with Grunt Uglify

I am trying to set the version in the filename with Grunt Uglify, but it doesn't accept anything other than a string literal.我正在尝试使用 Grunt Uglify 在文件名中设置版本,但它不接受字符串文字以外的任何内容。

How can I replace "VERSION" dynamically by using a variable (eg ${VERSION} ), or better yet, a command line argument?如何使用变量(例如${VERSION} )或更好的命令行参数来动态替换“VERSION”?

grunt.initConfig({

  uglify: {
    min: {
       options: {}
      ,files: {
        "jquery.project-VERSION.min.js" : [ "jquery.project.js", "modules/*.js" ]
      }
    }
    ,dev: {
       options: {
        beautify: {
          width: 80
        }
      }
      ,files: {
        "jquery.project-VERSION.dev.js" : [ "jquery.project.js", "modules/*.js" ]
      }
    }
  }
});

As pointed out in a comment by @cartant, this can be done with a Grunt template, eg <%= version %>正如@cartant 在评论中指出的那样,这可以通过 Grunt 模板来完成,例如<%= version %>

So in my case it was所以在我的情况下是

grunt.initConfig({

   version: 1.2.3    

  ,uglify: {
    min: {
       options: {}
      ,files: {
        "jquery.project-<%= version %>.min.js" : [ "jquery.project.js", "modules/*.js" ]
      }
    }
    ,dev: {
       options: {
        beautify: {
          width: 80
        }
      }
      ,files: {
        "jquery.project-<%= version %>.dev.js" : [ "jquery.project.js", "modules/*.js" ]
      }
    }
  }
});

Ref: Grunt > Configuring Tasks > Templates参考: Grunt > 配置任务 > 模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM