Skip to content

Support for staging builds #790

Description

@ehtb

Hi, I thought about adding support for staging builds. I am not sure if this requires ejecting though, or could be a feature of CRA.

Our use case is that we create staging builds to deploy to our staging servers. This allows us to debug the app in a production like environment, but with the benefit of non-minimised code including proper sourcemap support and still includes the development warnings and notifications, as well as devtools support.

It can look very similar to webpack.config.prod.js, but with changes to L52-L54 and removal of webpack.optimize.UglifyJsPlugin.

Activity

  1. gaearon commented on Sep 28, 2016

    @gaearon
    Contributor

    This is something worth considering for the future although I think we won’t add this near term.

    still includes the development warnings

    What is your use case for development warnings in staging builds?

  2. ehtb commented on Sep 28, 2016

    @ehtb
    Author

    What is your use case for development warnings in staging builds?

    Invariant warnings for instance, but also propType checks.

  3. gaearon commented on Sep 28, 2016

    @gaearon
    Contributor

    Invariant warnings for instance

    Which ones are you referring to? “Invariants” are not warnings, those are hard errors and exist both in production and development builds.

  4. ehtb commented on Sep 28, 2016

    @ehtb
    Author

    Sorry, I meant more descriptive errors in the case of invariants. It serves the same purpose though, by making errors / bugs more transparent.

  5. ehtb commented on Oct 4, 2016

    @ehtb
    Author

    I just pushed a first idea of how it could work. It uses the production Webpack config as a base and adds the relevant changes on top of it. Other than that it's mostly adding the proper scripts and small modifications. If you consider supporting it, let me know so I can create a pull request.

    An alternative option could be to add a minify flag (react-scripts build --minify=false). We would forego on React's warning etc., which are removed in the production build, but it would make errors more transparent / easier to debug in a staging environment.

  6. shin-monkey commented on Dec 19, 2016

    @shin-monkey

    YES @msmfsd ! We need this. Maybe make passible to set NODE_ENV as you like on the build.

    Something like:
    "NODE_ENV=WHATEVERYOUWANT npm run build"

  7. firaskrichi commented on Jan 18, 2017

    @firaskrichi

    What's the alternative right now when deploying? I mean how is it possible to set 'NODE_ENV=staging'

  8. eshinkawa commented on Jan 18, 2017

    @eshinkawa

    @firaskrichi create a .env file in the root folder of your application, with the variable you want. For eg.: REACT_APP_ENV=whatever

    console.log(process.env.REACT_APP_ENV) // will return "whatever".

  9. firaskrichi commented on Jan 18, 2017

    @firaskrichi

    I meant when deploying. Seems that NODE_ENV is set to production when deploying.

  10. eshinkawa commented on Jan 18, 2017

    @eshinkawa

    @firaskrichi indeed.

    The only way I could find to control my environments was through custom vars. Since I use Jenkins, I created scripts to build the .env file according to my environment needs.

    Right know NODE_ENV is 'development' before building, and 'production' after. You can't edit it.

  11. firaskrichi commented on Jan 18, 2017

    @firaskrichi

    I just set custom vars on Heroku and it works. Thanks @angusyoung84

  12. mderazon commented on Feb 23, 2017

    @mderazon
    Contributor

    I can confirm that during build time (yarn run build) NODE_ENV is hard coded to 'production'. It doesn't help if you set NODE_ENV to something else via shell / .env file.

    @gaearon wouldn't it make more sense if NODE_ENV found in shell / .env will have precedence and fallback to 'production' during build time ?

  13. gaearon commented on Feb 23, 2017

    @gaearon
    Contributor

    No, this is a dangerous footgun and will result in people unknowingly deploying development builds to production. Unfortunately I've seen this enough times to know it has to be hardcoded, and if we want to expose a separate build mode, it needs a separate command that you wouldn't confuse with a regular build.

  14. 75 remaining items

  15. sytolk commented on Aug 10, 2022

    @sytolk

    With resct-scripts v5 work this in react-scripts/scripts/build.js. It will force webpack development build

    // Generate configuration
    const config = configFactory('development'); // configFactory('production');
  16. el-j commented on Dec 22, 2022

    @el-j
    1. convert your lockfile to version 2
    npm shrinkwrap --lockfile-version 2
    
    1. edit node_modules/react-scripts/scripts/build.js
      and change line 12 | 13 + 58:
    // process.env.BABEL_ENV = "production"
    // process.env.NODE_ENV = "production"
    process.env.BABEL_ENV = process.env.NODE_ENV
    process.env.NODE_ENV = process.env.NODE_ENV
    
    // const config = configFactory("production"); 
    const config = configFactory(process.env.NODE_ENV);
    1. use patch-package to create a patch:
    npx patch-package react-script
    
    1. package.json change build and add build-dev + postinstall patch
    "scripts": {
    ...
    "build": "NODE_ENV=production react-scripts build",
    "build-dev": "NODE_ENV=development react-scripts build",
    "postinstall": "npx patch-package"
    ...
    },

    thanks for the idea @sytolk @chaosmirage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions