New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Staging vs production environment #1979
Comments
Short answer: You want your client-side assets to be built "as if it were Long answer: #1212 (comment) Here is the line where your `staging` is being overwritten, just in case you wanted to make a PR or change yourself: Line 18 in 227661b
With that said, I would not characterize this as an issue with Webpacker, it just needs better documentation. Like here:
|
@jakeNiemiec Yea I guess from compilation point of view But in our code, we are doing something like this. I am new to React/Webpacker, so perhaps theres a better way of doing this? switch (process.env.NODE_ENV) {
case 'production':
apiUrl = `https://server.com`;
break;
case 'staging':
apiUrl = `https://staging.server.com`;
} |
What about Or you could even do: const DEFAULT_API_URL = `https://server.com`;
apiUrl = process.env.API_URL || DEFAULT_API_URL; |
Yea thats why I did as a temp fix. But I will nice to have no rails dependency in JS code. |
@kapso Hey, As pointed out by Jake, please use env variables to set these options - https://12factor.net/config. You don't need Rails env then, just have different |
@gauravtiwari thanks, but that doesn't mean that this doesn't need fixing, right? Line 18 in 227661b
|
I believe Gaurav is saying that having more environment names would be worse than forcing you to use the Unknown to many Rails users: Angular, React and others have separate internal modes of operation based on Thus, you are given the option to set it to either based on what you are currently testing in staging:
Hope this helps. |
No that's correct because we don't want to support anything beyond standard environments for nodeJS world. As clearly explained by Jake, standard environment names have specific meaning for various libraries, example: React will optimise the build if set to "production", whereas "staging" has no meaning. The same applies to Webpack as well. Therefore, please use standard environment names as For example: |
Sounds good. @gauravtiwari @jakeNiemiec I will make a point however is what you have here is a "mode" not environment. Meaning it's ok to have different environments (staging, production, sandbox etc) but all represent the same mode i.e |
process.env.NODE_ENV
returnsproduction
(not "staging") even though I have the following environment variableNODE_ENV=staging
on my staging app.This is on Heroku, so not sure if this is a Heroku issue or Webpacker.
4.0.1
for both the gem and npm library, and on Rails5.2.2
staging:
configuration inwebpacker.yml
which looks likeproduction:
config/webpack/staging.js
-EDIT: looks like definitely a Webpacker issue. I ran Heroku bash console to check
process.env.NODE_ENV
and looks ok to me, but somehow Webpacker is not picking it.The text was updated successfully, but these errors were encountered: