Skip to content

Cannot run production build for ejected projects #5229

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

Closed
dagi12 opened this issue Mar 4, 2017 · 15 comments
Closed

Cannot run production build for ejected projects #5229

dagi12 opened this issue Mar 4, 2017 · 15 comments

Comments

@dagi12
Copy link

dagi12 commented Mar 4, 2017

Problem

I think title is quite self-explanatory here. Before app ejection I run
ng build -prod
For building production app. Unlike usual build this minify my project and does some other things.
After ejection there is a webpack configuration which as I think corresponds to usual build. There's no webpack configuration for production environment.

Possible fix

Project ejection should create production webpack configuration that will reflects ng build -prod behavior. And add webpack --config -p webpack.config.prod.js to scripts in package.json

@dagi12 dagi12 closed this as completed Mar 4, 2017
@hansl
Copy link
Contributor

hansl commented Mar 4, 2017

You can do this by using ng eject --prod. The eject command runs with the same flags as the build command.

@dagi12
Copy link
Author

dagi12 commented Mar 6, 2017

I've already figure this out. That's why I closed the issue ;)

@27leaves
Copy link

27leaves commented Jun 26, 2017

OK I think don't understand how eject is meant to be... Why can't I eject the project and have a development AND production environment afterwards?
I thought eject is like you do it once and then you cannot use angular-cli features anymore, but you're more flexible in configuration? So how am I supposed to make custom changes (#5362 (comment)) and build for development and production afterwards?
Thank's for every help!

@bennett000
Copy link

@creat-or you can it's just how you do so can get opinionated pretty quickly.

One common approach is to to have an environment variable , like NODE_ENV and set it prior to builds. Then in your webpack config test against it like const isProd = process.env.NODE_ENV === 'production' ? true : false;

Then later in your config you can use isProd to make choices about what plugins to use etc...

Taking a deeper dive would go waaay off topic. I bet there are blog posts about this somewhere.

@khalid-elabbadi
Copy link

i think in an angular-cli ejected project the command yarn run build (npm run build) must be smart and read arguments --prod -aot and pass them to webpack. That way things will run better and we stay on the same path as ng build options

@lifenautjoe
Copy link

lifenautjoe commented Oct 27, 2017

Can we re-open this? @dagi12.

Also whenever you do an ng eject --prod you must manually remove all package.json scripts and the webpack.config.jsfile in order for it to work.

@dagi12
Copy link
Author

dagi12 commented Oct 28, 2017

Reopened

@PeterShershov
Copy link

Hey guys, any progress regarding this?

@vincentjames501
Copy link
Contributor

+1. Seems like ng eject should allow passing similar arguments to webpack for generating a production build.

@hikumealan
Copy link

hikumealan commented Feb 1, 2018

+1 Additionally, I would like to see --code-coverage supported on the test command.

@bennett000
Copy link

@hikumealan I think the code coverage in CLI works out of the box, at least with HTML/lcov. Plus IIRC the karma config is customizable with or without ejecting.

@hansl hansl removed their assignment Feb 6, 2018
@ghost
Copy link

ghost commented Mar 20, 2018

I ran into this issue after running ng eject and found this issue. It isn't very difficult to work around, just more hassle than it should be and shouldn't require a workaround at all.

IMHO running ng eject should spit out a webpack.dev.config and a webpack.prod.config. It should also create npm scripts for build:prod, and watch, in addition to the other scripts it creates.

So until an official solution presents itself, here's my workaround.

  1. run ng eject
  2. rename webpack.config.js to webpack.dev.config.js
  3. delete all the npm scripts in package.json
  4. run ng eject --prod
  5. (optional) rename the new webpack.config.js to webpack.prod.config.js
  6. setup your npm scripts in package.json
  7. run npm i

And here is what my npm scripts look like when I'm done.

"scripts": {
    "build": "webpack --config webpack.dev.config",
    "watch": "webpack --watch --config webpack.dev.config",
    "build:prod": "webpack --config webpack.prod.config",
    "start": "webpack-dev-server --port=4200 --config webpack.dev.config",
    "test": "karma start ./karma.conf.js",
    "pree2e": "webdriver-manager update --standalone false --gecko false --quiet",
    "e2e": "protractor ./protractor.conf.js"
  }

@phil123456
Copy link

phil123456 commented Apr 25, 2018

it would be way more productive to be able to customize ng CLI build script instead of trying to merge dev/prod (generated) scripts based the the ENV variable

the differences between the two generated files are huge and such a process is really prone to mistakes

so far I copy 2 versions (dev and prod) of the ejected web pack config and the create a new webpack.config.js file:

if(process.env.npm_lifecycle_event=='build')
{
  module.exports = require('./dev.config');
}
else if(process.env.npm_lifecycle_event=='build-prod')
{
  module.exports = require('./prod.config');
}

//----------------------------------------------------------------------------------------------------------

// here I eventualy modify  "module.exports" variable
...

so I can update cli and redo the ejection if needed and have a separate custom config

@clydin
Copy link
Member

clydin commented Sep 28, 2018

eject functionality is no longer available in the latest version (6.0+). For custom webpack configurations the following unofficial add-on is a suggested solution: https://github.com/manfredsteyer/ngx-build-plus

@clydin clydin closed this as completed Sep 28, 2018
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests