Make possible to pass AST replacement values via command line arguments #346

wants to merge 2 commits into


None yet
3 participants

eeroan commented Jan 13, 2013

Any value with commas will be treated as array. This way the following command will inject the version number for a library:

node r.js -o build.js uglify.defines.VERSION=string,1.0

eeroan added some commits Jan 13, 2013

@eeroan eeroan Fix path in example of running tests e006e4f
@eeroan eeroan Allow usage of arrays as values from any comma separated values passe…
…d as command line arguments

This permits for example injecting version number to minified version of a library with this kind of command:
node r.js -o build.js uglify.defines.VERSION=string,1.0

jrburke commented Jan 15, 2013

Thanks for taking the time to look at the code and do a pull request.

I do not want to restrict values to always being arrays if they have a comma in them. There is already one, rawText, where it could have a comma but it is part of a string. While it is unlikely that rawText would be used on the command line, I also do not want to prevent commas from any future props.

Using a build.js file is suggested instead for these situations.

I have updated the to have your typo fix.

jrburke closed this Jan 15, 2013

eeroan commented Jan 15, 2013

In my case ./ 3.0.0 adds version number to the code, minifies, does a commit and creates a git tag.
That's why it needs to be command line argument. I have couple more options in mind:

  1. Allow list values for keys starting with uglify.defines
  2. Force users to escape commas from strings
  3. Have a black list of keys that have rawText values
  4. Treat values as rawText when using quotes

What do you think?

jrburke reopened this Jan 21, 2013

hagayl commented Aug 13, 2013

Is there a command-line alternative, as of today, for passing array values for uglify? Something that can replace a build.js file that contains the following:

uglify: {
    defines: {
        VERSION: ['string', ''],
        ENV: ['string', 'QA']

Currently the following line throws a "TypeError: Cannot call method 'apply' of undefined" exception:
node r.js -o build.js uglify.defines.ENV=string,QA

It would be very useful to have it, as build processes are often ran by scripts and it should be possible to control these uglify attributes dynamically.


jrburke commented Aug 14, 2013

This ticket is about possibly allowing that in the future, but does not work today.

@jrburke jrburke modified the milestone: 2.2.0, 3.0 Mar 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment