How to work with ngcli after ejecting the webpack

2019-02-19 22:54发布

问题:

I need to customise the webpack pack build in an Angular cli project. In order to configure I eject the webpack config file.

ng eject

Once I do that I can no longer run webpack build and serve command as I get the following error.

An ejected project cannot use the build command anymore

If the build commands can not be used after eject then what is the best way to work with webpack after eject.

回答1:

When you run the ng eject command this is the output that is displayed at the prompt:

ng eject
==========================================================================================
Ejection was successful.

To run your builds, you now need to do the following commands:
   - "npm run build" to build.
   - "npm run test" to run unit tests.
   - "npm start" to serve the app using webpack-dev-server.
   - "npm run e2e" to run protractor.

Running the equivalent CLI commands will result in an error.

==========================================================================================
Some packages were added. Please run "npm install".

Everything you need to know, right there.

Have a look inside the package.json to see the updates to the scripts section. There are a couple more commands there that are not shown in the output above.

Hope this helps.

UPDATE:

In case anyone was not aware, the CLI can still be used to generate code even after the eject has been done.

Commands like ng generate component blah will still work.