因为项目是Ionic2,为了加快App启动速度,打开命令Ionic build android --prod生成的时候报错,因为报错是插件的问题,所以就想升级到Ionic3,之后再打包就成功了。
下面是升级Ionic3的步骤:
1.更改项目中package.json中dependencies和devDependencies的版本号,如下面所示。
"dependencies": {
"@angular/common":
"4.1.0",
"@angular/compiler":
"4.1.0",
"@angular/compiler-cli":
"4.1.0",
"@angular/core":
"4.1.0",
"@angular/forms":
"4.1.0",
"@angular/http":
"4.1.0",
"@angular/platform-browser":
"4.1.0",
"@angular/platform-browser-dynamic":
"4.1.0",
"@ionic-native/barcode-scanner":
"^3.10.2",
"@ionic-native/camera":
"^3.10.2",
"@ionic-native/core":
"3.7.0",
"@ionic-native/splash-screen":
"^3.7.0",
"@ionic-native/status-bar":
"3.7.0",
"@ionic/storage":
"2.0.1",
"ionic-angular":
"3.2.1",
"ionicons":
"3.0.0",
"rxjs":
"5.1.1",
"sw-toolbox":
"3.6.0",
"zone.js":
"0.8.10"
},
"devDependencies": {
"@ionic/app-scripts":
"1.3.7",
"@ionic/cli-plugin-cordova":
"1.1.2",
"typescript":
"2.2.1"
},
2.运行命令
npm clear cache 清除npm缓存
npm install重新生成依赖注入
3.然后在app.module.ts中的导入 BrowserModule 和 HttpModule.
import {
BrowserModule }
from
'@angular/platform-browser';
import {
HttpModule }
from
'@angular/http';
imports: [
HttpModule,
BrowserModule,
IonicModule.
forRoot(
MyApp, {
tabsHideOnSubPages:
true}),
IonicStorageModule.
forRoot()
],
4.如果之前项目有引用native的插件,需要在官网相对应的native(Ionic官网)插件中,重新使用命令保存。
5.ionic serve运行项目看是否有错误,如果没有就继续打包啦,如果有就自己解决去解决啦(PS:我是没有报错的了...)
6.然后运行打包命令:ionic build android --prod
但是在这个时候报错了,好像是因为Ionic3更改了打包的命令为ionic cordova build android --prod 到这就没有问题了