jlengstorf / learn-rollup

This is an example project to accompany a tutorial on using Rollup.
https://code.lengstorf.com/learn-rollup-js/
ISC License
191 stars 61 forks source link

Under Setting ENV, command is different for PowerShell #30

Closed russdawginteractive closed 7 years ago

russdawginteractive commented 7 years ago

When going through your article, I was using Visual Studio Code for windows. In that app, it shells out to PowerShell within the application. In order to get the environment setting to work properly, I had to run this: $env:NODE_ENV="production"; ./node_modules/.bin/rollup -c

When I tired to use your command as outlined below within a regular command window, it did not work, it only set the NODE_ENV variable to be actually "production ./node_modules/.bin/rollup".

NOTE: On Windows, use SET NODE_ENV=production ./node_modules/.bin/rollup -c to avoid an error setting environment variables.

I found this solution via StackOverflow at this location: http://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-in-windows

jlengstorf commented 7 years ago

@russdawginteractive Could you do me a favor and try this?

SET NODE_ENV="production" ./node_modules/.bin/rollup -c

I'm wondering if it's a lack of quotes that caused that issue.

russdawginteractive commented 7 years ago

@jlengstorf It's strange. That does not work in either Powershell or a regular command window. I created a quick link to show you what I'm seeing when I run the command you suggest.

https://www.screencast.com/t/cBHdHmE0cmHm

jlengstorf commented 7 years ago

@russdawginteractive I don't have Flash, and it appears screencast.com requires that plugin, so I can't see the video.

However, I've added a note to the article referencing this issue for anyone on Windows who hits the same snag. Thanks for sharing!

russdawginteractive commented 7 years ago

As a follow up, I came across this same issue on another project. Upon doing some further research, I found that using the command below works in Powershell: set NODE_ENV=production&&./node_modules/.bin/rollup -c

Alternatively, there is a plugin called cross-env that will work across systems: https://www.npmjs.com/package/cross-env

dance2die commented 6 years ago

One important thing to note is that there should be no space between NODE_ENV=production and &&. But you can have spaces after && as shown below.

"scripts": {
    "build": "rollup -c",
    "buildprod": "SET NODE_ENV=production&& rollup -c"
  },

If you have a space before &&, windows adds the space to NODE_ENV. So the value will be set to production <- notice the space. therefore it won't work.

jlengstorf commented 6 years ago

I think an easier solution to this would be to use https://www.npmjs.com/package/cross-env

If someone wants to submit a PR, I'd be much obliged.