codesandbox-client
codesandbox-client copied to clipboard
Being able to run sandboxes in production mode
🌈 Feature
Quoting Dan Abramov on Twitter:
at least, for React, just switching NODE_ENV is enough. Maybe offer an option?
I wasn't aware that csb isn't running in prod, had no idea that dev mode in general has this kind of impact: https://twitter.com/dan_abramov/status/1136526025393754112
The original demo is here: https://codesandbox.io/s/peaceful-johnson-txtws it goes so slow that it's barely moving at all.
I am mostly using csb for presentational matters, when you want to demonstrate a library in the best light or some functionality. It would be nice to know the underlying framework's doing its best. 🙂
Good point! The tricky thing about enabling "production mode" is that we don't do the uglifying/tree-shaking, so we need to communicate clearly that we're only changing the environment variable there and that it doesn't reflect real prod apps.
There are two ways I can think of making this work:
- We add it as an option to
sandbox.config.json - We fix the sandbox if
NODE_ENV=productionin.envfile. We do support.envfiles right now, but I added a hardcoded optimization to only include the dev bundle in the case of React. That's why this doesn't work: https://codesandbox.io/s/jovial-jepsen-efe8f. I can remove the optimization in case of a changed env variable, it would also be good to document this better.
Both seem like a good way, thanks for considering this Ives!
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
still much needed :-)
True, removing the label
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.
This issue has been automatically closed because there wasn't any activity after the previous notice or the stale label wasn't removed.
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.
Bump
We used to be able to do this by deploying to Netlify or Vercel. It seems that these options were removed.
Yep. We haven't reimplemented Netlify/Vercel yet with the new APIs. In the meantime, it is possible to do this with devboxes. You can do this either by:
- Running the dev server in prod mode
- Deploying from the terminal
- Connecting the project to a GitHub repository and set up an automated flow from there
For adding a production mode to sandboxes, it should now be easier because AFAIK the hardcoded dev mode is not there anymore. The resulting preview will not be "real" production mode (with tree shaking etc), but it will run the production version of React.
Actually, looking at the code, it looks like we already do support NODE_ENV from .env (code here). So it should not be much extra to support production mode! I can experiment with this.