撤回Angular CLI执行的ng eject
使用angular cli执行ng eject后,就不允许执行ng server或ng build。
执行ng server 或ng build会报一下错误:
An ejected project cannot use the build command anymore.
错误信息的出处
查看源码,你可以在
https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/tasks/build.ts#L27
以及
https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/tasks/serve.ts#L66
定位到错误提示的出处:
if (config.project && config.project.ejected) {
throw new SilentError('An ejected project cannot use the build command anymore.');
}
ng eject执行后的变动
1、执行ng eject后,你会发现在package.json发生了改变
原来
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}
执行ng eject后
"scripts": {
"ng": "ng",
"start": "webpack-dev-server --port=4200",
"build": "webpack",
"test": "karma start ./karma.conf.js",
"lint": "ng lint",
"e2e": "protractor ./protractor.conf.js",
"pree2e": "webdriver-manager update --standalone false --gecko false --quiet"
}
2、在根目录生成了webpack.config.js文件
3、在.angular-cli.json的project属性新增了ejected,如下
"project": {
"name": "项目名",
"ejected": true
}
解决方法
为了可以重新使用ng的命令,只需要在.angular-cli.json中,把ejected删除或者把它的值改为false
"project": {
"name": "项目名",
"ejected": false
}