Skip to main content

安装 Ionic

Ionic 应用主要通过 Ionic 命令行 工具创建和开发。Ionic CLI 是推荐的安装方法,因为它在开发过程中提供了广泛的开发工具和帮助选项。它也是运行应用并将其连接到其他服务(如 Appflow)的主要工具。

🌐 Ionic apps are created and developed primarily through the Ionic command-line utility. The Ionic CLI is the preferred method of installation, as it offers a wide range of dev tools and help options along the way. It is also the main tool through which to run the app and connect it to other services, such as Appflow.

Try our App Wizard

Use our App Wizard to generate an Ionic project visually. Choose a template, custom colors, app icon, and JavaScript Framework to get building quicker.

安装 Ionic CLI

🌐 Install the Ionic CLI

在继续之前,请确保你的计算机已安装 Node.js。请参阅 这些说明 来为 Ionic 设置环境。

🌐 Before proceeding, make sure your computer has Node.js installed. See these instructions to set up an environment for Ionic.

使用 npm 安装 Ionic CLI:

🌐 Install the Ionic CLI with npm:

npm install -g @ionic/cli

如果以前安装过 Ionic CLI,则由于包名称发生更改,需要将其卸载。

🌐 If there was a previous installation of the Ionic CLI, it will need to be uninstalled due to a change in package name.

$ npm uninstall -g ionic
$ npm install -g @ionic/cli

note

-g 选项意味着 全局安装。当软件包全局安装时,可能会出现 EACCES 权限错误。考虑设置 npm 以在没有提升权限的情况下全局运行。更多信息请参见 解决权限错误

启动应用

🌐 Start an App

使用预制的应用模板之一创建一个 Ionic 应用,或者使用空白模板从头开始。三种最常用的启动模板是 blank 启动模板、tabs 启动模板和 sidemenu 启动模板。使用 ionic start 命令开始:

🌐 Create an Ionic app using one of the pre-made app templates, or a blank one to start fresh. The three most common starters are the blank starter, tabs starter, and sidemenu starter. Get started with the ionic start command:

ionic start

Three thumbnail previews of Ionic app templates: blank, tabs, and side menu.

要了解有关启动 Ionic 应用的更多信息,请参阅 入门指南

🌐 To learn more about starting Ionic apps, see the Starting Guide.

运行应用

🌐 Run the App

大部分 Ionic 应用开发可以直接在浏览器中使用 ionic serve 命令进行:

🌐 The majority of Ionic app development can be spent right in the browser using the ionic serve command:

$ cd myApp
$ ionic serve

还有许多其他运行应用的方法,建议从此工作流程开始。要在设备和模拟器上开发和测试应用,请参阅 运行应用指南

🌐 There are a number of other ways to run an app, it's recommended to start with this workflow. To develop and test apps on devices and emulators, see the Running an App Guide.