Angular-cli: Request - set NODE_ENV="production" on prod build/serve

Created on 14 Sep 2016  路  14Comments  路  Source: angular/angular-cli

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
    OSX 10.11.6
  2. Versions. Please run ng --version. If there's nothing outputted, please run
    in a Terminal: node --version and paste the result here:
    angular-cli: 1.0.0-beta.11-webpack.9-2
    node: 6.5.0
    os: darwin x64
  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.
    Include a npm package which uses React and run a prod-build/serve.
  4. The log given by the failure. Normally this include a stack trace and some
    more information.
    Warning: It looks like you're using a minified copy of the development build of React. When deploying React apps to production, make sure to use the production build which skips development warnings and is faster. See https://fb.me/react-minification for more details.
  5. Mention any other details that might be useful.
    This can be solved by setting the NODE_ENV to "production" on prod build (i.e. set process.env.NODE_ENV = 'production'; in build script). I'd be happy to submit a PR for this if interested.

Thanks! We'll be in touch soon.

3 (nice to have)

Most helpful comment

Thank you for solving this, didn't get to making the PR yet. Great that it's implemented now 馃憤

All 14 comments

@TheLarkInn can you weigh in?

@gaearon is there any other way to flip this flag? Just want to know our available options.

We just want process.env.NODE_ENV to be envified to become "production" in the bundled code. We don鈥檛 actually care about process.env.NODE_ENV of the build scripts, just that you DefinePlugin({ "process.env.NODE_ENV": "\"production\"" }) when you build.

Thank you very much, @gaearon. @filipesilva this would require a change, maybe falls into future add-on system. Though implementing this would likely not collide or conflict as the use case is probably edge.

ng build --prod Should set NODE_ENV to production by default, im having this exact issue with Redux. Any workarounds?

@TheLarkInn should this indeed use the future add-on system or is it ok to put this in the default production webpack configuration? Running into this issue as well, more then willing to put in a pull request.

Been trying to find a workaround for it without having to fork and run my own version of the angular-cli but running out of ideas.

Now that I think about it, can you not just set it manually via export NODE_ENV=production? You could even put it in a npm script export NODE_ENV=production && ng build -prod.

This seems to be a React specific thing and I'd rather not introduce changes to the build pipeline because of it.

@filipesilva Just tried your suggestion but it didn't seem to work for me.

"scripts": {
    "build": "export NODE_ENV=production && ng build --prod",
    "prepublish": "npm run build"
  }

Still results in

You are currently using minified code outside of NODE_ENV === 'production'.

That's because that check is being done runtime by Redux. What we need is the webpack define plugin to set NODE_ENV global variable within the bundle. It's not something React specific and it's probably gonna be needed for more packages.

@rthewhite I'll reopen then, but haven't had any report outside of React/Redux so far so I have to say this isn't very high on the priority list.

@filipesilva I can understand that it's not very high on the priority list. I'm more then willing to create a PR for it so you guys can see if it doesn't have any undesirable side effects and what the impact would be?

That would be welcome, yes. I could bring up the implementation among the team and see what we decide.

Thank you for solving this, didn't get to making the PR yet. Great that it's implemented now 馃憤

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings