angular-cli: Cannot run production build for ejected projects
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (3 by maintainers)
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.
ng eject
ng eject --prod
npm i
And here is what my npm scripts look like when I’m done.
You can do this by using
ng eject --prod
. The eject command runs with the same flags as the build command.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 asng
build optionsCan we re-open this? @dagi12.
Also whenever you do an
ng eject --prod
you must manually remove allpackage.json
scripts and thewebpack.config.js
file in order for it to work.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 thoughteject
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 (https://github.com/angular/angular-cli/issues/5362#issuecomment-310298275) and build for development and production afterwards? Thank’s for every help!