how to build static html as development environtment
when i build with command gatsby build it make static html as production build
in my case i need test development environtment and deploy to static site
in development process.env.NODE_ENV is development
console.log(process.env.NODE_ENV) when usinggatsby build NODE_ENV is production
thanks
@derit There currently isn't a documented way to build your site in development. gatsby build overrides NODE_ENV and sets it to production
Can you elaborate on what you're trying to achieve exactly?
@sidharthachatterjee
just need build gatsby static with development environment
@derit We don't support that unfortunately!
Closing this issue for now but please feel free to reopen or comment if there is anything else we can help with
We have some ideas how you could try to do this https://github.com/gatsbyjs/gatsby/issues/14230. It's not officially supported so we're not sure what sideffects this will give.
i solved this problem with refered to this document
https://www.gatsbyjs.org/docs/add-custom-webpack-config/#examples
using define plugin
exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions,
}) => {
actions.setWebpackConfig({
module: {
rules: [
],
},
plugins: [
plugins.define({
__DEVELOPMENT__: stage === `develop` || stage === `develop-html`,
}),
],
})
}
+1.
I want to build my website and deploy it using a development environment.
Why: I need to deploy and show the staging website to the users/customers, then they will be able to test and use it on the staging environment.
We should have a way to build and deploy a gatsby website for development/stage purposes, but currently, gatsby build automatically set the environment variable to Production.
Any thoughts on this @sidharthachatterjee?
Thanks!
@lucashfreitas I just stumbled upon this and found that you can set env vars prefixed with GATSBY_ and before running gatsby build. You can then access the variable in your javascript with process.env.GATSBY_MY_VAR. For example, I have set a env var to indicate the dev environment:
export GATSBY_APP_ENVIRON=dev
and then in one of my components:
if (process.env.GATSBY_APP_ENVIRON === "dev") {
// Do development specific things
}
More info here: https://www.gatsbyjs.org/docs/environment-variables/#example
Most helpful comment
+1.
I want to build my website and deploy it using a development environment.
Why: I need to deploy and show the staging website to the users/customers, then they will be able to test and use it on the staging environment.
We should have a way to build and deploy a gatsby website for development/stage purposes, but currently, gatsby build automatically set the environment variable to Production.
Any thoughts on this @sidharthachatterjee?
https://stackoverflow.com/questions/58280325/gatsby-build-website-for-stage-development-which-command-should-i-use
Thanks!