[英]Start a project in angular4 using cli
I want to start an angular4 project using angular CLI command. 我想使用angular CLI命令启动angular4项目。 I have tried using command : 我尝试使用命令:
ng new angular-sample --ng4
But it is telling 但这说明
The option '--ng4' is not registered with the new command. 选项'--ng4'未在新命令中注册。 Run
ng new --help
for a list of supported options. 运行ng new --help
以获得支持的选项列表。
And the above command creates angular2 project folder structure. 上面的命令创建了angular2项目文件夹结构。
Is there any way to start the angular4 without manually editing the angular 2 versions(> 4) in package.json
? 有什么方法可以在不手动编辑package.json
的angular 2版本(> 4)的情况下启动angular4吗?
If you're using Angular CLI 1.0.0-beta.28 or less. 如果您使用的是Angular CLI 1.0.0-beta.28或更低版本。 Please uninstall it using following commands 请使用以下命令将其卸载
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
Then do the global npm update by running the following command 然后通过运行以下命令进行全局npm更新
npm install -g @angular/cli@latest
if you want to upgrade your existing project then update the package.json 如果要升级现有项目,请更新package.json
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"jquery": "^3.3.1",
"rxjs": "^5.5.6",
"tether": "^1.4.3",
"zone.js": "^0.8.19"
},
Note: This package.json is angular 5. Change it if you need angular 4. 注意:这个package.json是有角度的5。如果需要有角度的4,请更改它。
Then run the npm install
然后运行npm install
When you create a new project using the cli it automatically resolves the dependencies to the latest version available in the npm. 使用cli创建新项目时,它会自动将依赖项解析为npm中可用的最新版本。 If you want to create a project with a specific version of Angular using the cli, my recommendation is to generate a new one and then manually downgrade the different versions editing the package.json
file. 如果要使用cli创建具有特定版本Angular的项目,我的建议是生成一个新项目,然后手动手动降级不同版本以编辑package.json
文件。 But be careful because you need to edit the different angular packages (`@angular/common", @angular/compiler", "@angular/core", ...). 但是要小心,因为您需要编辑不同的角度包(“ @ angular / common”,@ angular / compiler”,“ @ angular / core”,...)。 After editing run: 编辑运行后:
npm cache clean && npm install
What you can do is install any local version of angular-cli
and then 您可以做的是安装任何本地版本的angular-cli
,然后
In package.json
make a script for ng 在package.json
为ng编写脚本
"scripts": {
"ng": "ng"
}
Calling "npm run-script ng build"
will use the local version of the cli. 调用"npm run-script ng build"
将使用cli的本地版本。 It will work even if you haven't installed the cli globally. 即使您尚未全局安装cli,它也将起作用。
This way you can maintain different versions of angular-cli 这样,您可以维护不同版本的angular-cli
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.