ionic 筆記 - 初探


Posted by on December 25, 2018, modified on December 25, 2018

摘要 >


Installation >

For Dockefile to install nodejs and Android SDK

Nodejs Testing >

Run npm init to initial a testing package. Then, run npm install --save-dev ionic to install ionic into local package.

Because you install ionic into local package, so you need to add ionic command into "scripts" on package.json.

package.json

{
  "name": "ionicTest",
  "version": "1.0.0",
  "description": "", 
  "main": "index.js",
  "scripts": {
    "ionic": "ionic",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "ionic": "^4.10.3"
  }
} 

Create ionic.sh to use ionic in package.

ionic.sh

#!/bin/bash
[ ! -d 'node_modules' ] && npm install
npm run ionic -- ${@:1}

Get the ionic usage command.

./ionic.sh --help

Ionic usage:

  Global Commands:

    config <subcommand> ............. Manage CLI and project config values 
                                      (subcommands: get, set, unset)
    docs ............................ Open the Ionic documentation website
    info ............................ Print project, system, and environment 
                                      information
    init ............................ (beta) Initialize existing projects with 
                                      Ionic
    login ........................... Login to Ionic Appflow
    logout .......................... Logout of Ionic Appflow
    signup .......................... Create an account for Ionic Appflow
    ssh <subcommand> ................ Commands for configuring SSH keys 
                                      (subcommands: add, delete, generate, list, 
                                      setup, use)
    start ........................... Create a new project

Create a blank project by runnig ./ionic.sh start myApp blank --type=ionic1 command, and you will get myApp folder.

Add the same code into ‘package.json’ as below in myApp ionic package.

  "scripts": {
    "ionic": "ionic",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

Then, you can run ionic command by ionic.sh to generate Android APP.

$ ./ionic.sh cordova platform add android
$ ./ionic.sh cordova build android
本站總訪問量訪客