The Ionic command line interface (CLI) is your go-to tool for developing Ionic apps.
Use ionic --help for more detailed command information.
📣 Support/Questions? Please see our Support Page for general support questions. The issues on GitHub should be reserved for bug reports and feature requests.
❤️ Want to contribute? Please see CONTRIBUTING.md.
- Requirements
- Install
- Changes from CLI v2
- Getting Started
- Using Cordova
- Environment Variables
- CLI Flags
- CLI Hooks
- Service Proxies
- Using a Proxy
- Legacy Version
- Node 6 LTS (latest)
- npm 3+
$ npm install -g ionic📝 Note: For a global install -g ionic, macOS/Linux users may need to
prefix with sudo or can setup proper file permissions for
npm.
You can review the CLI v2 -> v3 upgrade notes in CHANGELOG.md.
$ npm install -g ionic@latest
$ ionic start myNewProject
$ cd ./myNewProject
$ ionic serve$ npm install -g ionic@latest
$ ionic start myNewProject blank --type=ionic1
$ cd ./myNewProject
$ ionic serveIntegrate Ionic with Cordova to bring native capabilities to your app.
- For iOS development, see the iOS Platform Guide.
- For Android development, see the Android Platform Guide.
$ npm install -g cordova
$ npm install --save-dev --save-exact @ionic/cli-plugin-cordova@latest
$ ionic --help
$ ionic cordova run iosThe CLI will look for the following environment variables:
IONIC_CONFIG_DIRECTORY: Where the CLI config files live. Defaults to~/.ionic. You may prefer~/.config/ionic.IONIC_HTTP_PROXY: Set a URL for proxying all CLI requests through. See Using a Proxy. The CLI will also look forHTTP_PROXYandHTTPS_PROXY, both of which npm use.IONIC_EMAIL/IONIC_PASSWORD: For automatic login via environment variables.
CLI flags are global options that alter CLI behavior.
--help: Instead of running the command, view its help page.--verbose: Show all log messages for debugging purposes.--quiet: Only showWARNandERRORlog messages.
The behavior that these flags set is remembered in the CLI config file.
--interactive/--no-interactive: Switch between interactive (default) and non-interactive mode. In non-interactive mode, the spinner and all prompts are disabled (useful for CI/CD servers).--confirm/--no-confirm: Switch between auto-confirmation and non-confirmation (default) of confirmation prompts. Careful: the CLI prompts before doing something potentially harmful. Auto-confirming may have unintended results.--timeout/--no-timeout: Switch between timeout (default) and non-timeout mode. In non-timeout mode, all requests timeout are disabled.
CLI hooks are how you can run scripts during CLI events, such as "watch" and
"build". To hook into the CLI, use the following npm
scripts in your package.json file:
| npm script | description | commands |
|---|---|---|
ionic:watch:before |
Runs before the file watcher activates during a "watch" event | ionic serve, ionic cordova run, ionic cordova emulate |
ionic:build:before |
Runs before the Ionic "build" event starts. | ionic upload, ionic package build, ionic cordova build |
ionic:build:after |
Runs after the Ionic "build" event finishes. | ionic upload, ionic package build, ionic cordova build |
"scripts": {
"ionic:build:before": "mv somefile www/somefile",
}📝 Note: Use gulp? Check out @ionic/cli-plugin-gulp.
The serve command can add some proxies to the HTTP server. These proxies are
useful if you are developing in the browser and you need to make calls to an
external API. With this feature you can proxy request to the external api
through the ionic http server preventing the No 'Access-Control-Allow-Origin' header is present on the requested resource error.
In the ionic.config.json file you can add a property with an array of proxies
you want to add. The proxies are object with the following properties:
path: string that will be matched against the beginning of the incoming request URL.proxyUrl: a string with the url of where the proxied request should go.proxyNoAgent: (optional) true/false, if true opts out of connection pooling, see HttpAgent
{
"name": "appname",
"email": "",
"app_id": "",
"proxies": [
{
"path": "/v1",
"proxyUrl": "https://api.instagram.com/v1"
}
]
}
Using the above configuration, you can now make requests to your local server
at http://localhost:8100/v1 to have it proxy out requests to
https://api.instagram.com/v1.
To proxy CLI requests, you will need to install the global CLI proxy plugin:
$ npm install -g @ionic/cli-plugin-proxyThen, set the following environment variables:
$ export HTTP_PROXY=http://internal.proxy.com # used by npm
$ export HTTPS_PROXY=https://internal.proxy.com # used by npm
$ export IONIC_HTTP_PROXY=http://internal.proxy.comFor example:
$ HTTPS_PROXY=https://internal.proxy.com ionic startThe old version of the CLI can be installed with the legacy tag:
npm install -g ionic@legacy