hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
902 stars 57 forks source link

using envify purge option in package.json browserify field #26

Open andineck opened 9 years ago

andineck commented 9 years ago

It took me a while to get the envify purge option right inside the package.json.

I'm just posting it here for reference.

  "browserify": {
    "transform": [
      ["brfs"],
      ["envify", {"_": "purge"}]
    ]
  },

note: brfs is not needed, it's just showing how to add several transforms.

yoshuawuyts commented 9 years ago

Neat, thanks for posting this as it may definitely help others. Might be rad to add this to the README.

joshgillies commented 8 years ago

I also just came across this, and totally It's great to have the ability to set this value in this way. I do wonder whether it might be worth a refactor to support:

  "browserify": {
    "transform": [
      ["brfs"],
      ["envify", {"purge": true}]
    ]
  }

At the very least adding something to the README to highlight this would be ideal. :)

Probably worth a ref: #29

casr commented 8 years ago

I’ve noticed that I can’t override the environment variable if I specify it in the transform. With this in the browserify.transform key:

"browserify": {
  "transform": [
    ["envify", {"_": "purge", "NODE_ENV": "from transform"}]
  ]
}

and then running:

% NODE_ENV='from env' browserify .

will produce the output with process.env.NODE_ENV being replaced with "from transform". However, if you do not have a browserify.transform key specified and you run:

% NODE_ENV='from env' browserify . -t [ envify purge --NODE_DEV 'from args' ]

you will see process.env.NODE_ENV being replaced with "from env".

I’ve created a test repository if anyone wants to try it out. What‘s the right behaviour here?

thinkloop commented 7 years ago

Anyone have an idea if package.json config can be used for props other than transform, like detectGlobals, or similar:

  "browserify": {
    "transform": [
      ["babelify"]
    ],
    detectGlobals: false
  },