Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

cross-env not working with webpack command? #13

Closed
mikechabot opened this issue Feb 22, 2016 · 6 comments
Closed

cross-env not working with webpack command? #13

mikechabot opened this issue Feb 22, 2016 · 6 comments

Comments

@mikechabot
Copy link

I feel I may be implementing this incorrectly. The first command properly sets my NODE_ENV variable, however the second does not. What am I missing? Server.js provided below.

> cross-env NODE_ENV=production node server.js

Listening at localhost:3040 in production mode

As we can see, I'm now running in production mode, however if I add in the webpack command, which is noted in the example command on https://www.npmjs.com/package/cross-env, it doesn't work. (Note: NODE_ENV not found, defaulting to development)

> cross-env NODE_ENV=production webpack --config webpack.config.js && node server.js

Hash: ee27fe5be08b7d0e882f
Version: webpack 1.12.13
Time: 6720ms
                               Asset       Size  Chunks             Chunk Names
9c786af43b89a8223d3aadd741346079.png    10.5 kB          [emitted]
                           bundle.js    3.71 MB       0  [emitted]  main
                          index.html  662 bytes          [emitted]
   [0] multi main 52 bytes {0} [built]
    + 855 hidden modules
NODE_ENV not found, defaulting to development
Listening at localhost:3040 in dev mode

However, if I just use the following, everything works as expected:

> set NODE_ENV=production&& webpack --config webpack.config.js && node server.js

Hash: ee27fe5be08b7d0e882f
Version: webpack 1.12.13
Time: 6712ms
                               Asset       Size  Chunks             Chunk Names
9c786af43b89a8223d3aadd741346079.png    10.5 kB          [emitted]
                           bundle.js    3.71 MB       0  [emitted]  main
                          index.html  662 bytes          [emitted]
   [0] multi main 52 bytes {0} [built]
    + 855 hidden modules
Listening at localhost:3040 in production mode

Server.js

const isProduction = process.env.NODE_ENV === 'production';
if (!isProduction) {
    console.log('NODE_ENV not found, defaulting to development');
}

new WebpackDevServer(webpack(config), {
  hot: true,
  historyApiFallback: true
}).listen(3040, 'localhost', function (err, result) {
  if (err) {
    console.log(err);
  }
  console.log(`Listening at localhost:3040 in ${isProduction ? 'production' : 'dev'} mode`);
});
@kentcdodds
Copy link
Owner

Huh, that's very odd. Do you have a repo where I can see this in action?

@mikechabot
Copy link
Author

I'll slap one together later tonight.

@mikechabot
Copy link
Author

Hey, just put together the example repo below specifically for this issue, so hopefully that'll help localize the problem:

https://github.com/mikechabot/cross-env-example

And I tried to document as much as I could in the README, but let me know if you hit any issues, or if I'm simply doing something incorrect, or if you have any questions. Of the scripts documented, you'll probably be interested in the following three:

start-dev-cross --> Like the first command noted in my original comment
start-dev-cross-webpack --> Like the second command noted in my original comment
start-dev-set --> Like the third command noted in my original comment

@mikechabot
Copy link
Author

Oh, and no rush.

@kentcdodds
Copy link
Owner

Sorry it took so long, but here's the solution: mikechabot/cross-env-example#1

@mikechabot
Copy link
Author

Great, thanks very much for taking a look; I knew it'd be something on my end!. Thanks again, and great lib!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants