2017年4月12日 星期三

Ionic 3 is released!!!

因應JavaScript推出ES6標準的重大變革,AngularJS改版推出Angular 2,這使得Ionic也順勢改版為Ionic 2,將支援ES6的Angular 2納入。2017年1月Ionic 2.0.0正式版推出;短短兩個月便修正到2.3.0版,改正不少bugs,效能也有所提昇。不過,2.x.x版大家都還沒玩透,4月初,Ionic 3.0.0便又推出了!(官方部落格:Ionic 3.0 has Arrived!

究竟為何Ionic如此迅速改版?原來是因為Angular 4推出的緣故!什麼?Angular 2不是才剛出,怎麼馬上就變4.0.0??? 這就要提到SemVer了。SemVer是一種軟體版本編號的規範(詳情請參考Semantic Versioning),簡言之,軟體版本由三個數字組成,例如3.0.0,依序代表Major, Minor與Patch的編號。Angular 2做了TypeScript版本 dependency的升級,因此改Major序號為4(跳過3直接到4是因為要將Angular眾多子函式庫的版本統一到4版),這也是為什麼Ionic要從2跳至3版的主要原因。

所以,Ionic 3.0.0到底跟Ionic 2.3.0有何差別?Ionic 2的專案要注意哪些事項?根據Ionic Github網頁的Change Log,舊的2.x.x專案必須:
  1. 更新package.json內容如下:
    "dependencies": {
        "@angular/common": "4.0.0",
        "@angular/compiler": "4.0.0",
        "@angular/compiler-cli": "4.0.0",
        "@angular/core": "4.0.0",
        "@angular/forms": "4.0.0",
        "@angular/http": "4.0.0",
        "@angular/platform-browser": "4.0.0",
        "@angular/platform-browser-dynamic": "4.0.0",
        "@ionic-native/core": "3.4.2",
        "@ionic-native/splash-screen": "3.4.2",
        "@ionic-native/status-bar": "3.4.2",
        "@ionic/storage": "2.0.1",
        "ionic-angular": "3.0.1",
        "ionicons": "3.0.0",
        "rxjs": "5.1.1",
        "sw-toolbox": "3.4.0",
        "zone.js": "^0.8.4"
    },
    "devDependencies": {
      "@ionic/app-scripts": "1.3.0",
      "typescript": "~2.2.1"
    }
    
    然後移除 node_modules 內所有內容,再重跑一次npm install,帶入新版的dependencies。
  2. 修改app/app.module.ts內容,將BrowserModule import進來,如下:
    import { BrowserModule } from '@angular/platform-browser';
    ...
    [略]
    ...
    imports: [
      BrowserModule,
      ...
    ],
  3. 如果有用到Http,則同樣要改app/app.module.ts,加入:
    import { HttpModule } from '@angular/http';
    ...
    [略]
    ...
    imports: [
      BrowserModule,
      HttpModule,
      ...
    ],

所以,Ionic 3其實變化不大,只是隨著Angular 4推出,而將相關module升級,支援更新版本的TypeScript而已。

最後,根據SemVer規範,恐怕Angular很快又會有新的Major版本出現,屆時如果Ionic變成Ionic 4甚至Ionic 5,大家也就不要大驚小怪了。


沒有留言:

張貼留言