Updating to Ionic 4
Updating from Ionic 3 to 4
This guide assumes that you have already updated your app to the latest version of Ionic 3. If you are using Ionic 1 or 2, Make sure to follow the Updating from Ionic 1 to 4 Guide instead.
For a complete list of breaking changes from Ionic 3 to Ionic 4, please refer to the breaking changes document in the Ionic Framework repository.
We suggest the following general process when migrating an existing application from Ionic 3 to 4:
- Generate a new project using the
blank
starter (see Starting an App) - Copy any Angular services from
src/providers
tosrc/app/services
- Services should include
{ providedIn: 'root' }
in the@Injectable()
decorator. For details, please see Angular provider docs.
- Services should include
- Copy the app's other root-level items (pipes, components, etc) keeping in mind that the directory structure changes from
src/components
tosrc/app/components
, etc. - Copy global Sass styling from
src/app/app.scss
tosrc/global.scss
- Copy the rest of the application, page by page or feature by feature, keeping the following items in mind:
- Emulated Shadow DOM is turned on by default
- Page/component Sass should no longer be wrapped in the page/component tag and should use Angular's
styleUrls
option of the@Component
decorator - RxJS has been updated from v5 to v6 (see RxJS Changes)
- Certain lifecycle hooks should be replaced by Angular's hooks (see Lifecycle Events)
- Markup changes may be required (migration tool available, see Markup Changes)
In many cases, using the Ionic CLI to generate a new object and then copying the code also works very well. For example: ionic g service weather
will create a shell Weather
service and test. The code can then be copied from the older project with minor modifications as needed. This helps to ensure the proper structure is followed. This also generates shells for unit tests.
Changes in Package Name
In Ionic 4, the package name is @ionic/angular
. Uninstall Ionic 3 and install Ionic 4 using the new package name:
$ npm uninstall ionic-angular
$ npm install @ionic/angular@v4-lts
While migrating an app, update the imports from ionic-angular
to @ionic/angular
.
Project structure
One of the major changes between an Ionic 3 app and an Ionic 4 app is the overall project layout and structure. In v3, Ionic apps had a custom convention for how an app should be set up and what that folder structure should look like. In v4, this has been changed to follow the recommended setup of each supported framework.
For example, if an app is using Angular, that project structure will be exactly what an Angular CLI app would be. This change, while not too difficult to accommodate, helps to keep common patterns and documentation consistent.
- Ionic 4
- Ionic 3
src/
├── app/
│ ├── about/
│ ├── home/
│ ├── app-routing.module.ts
│ ├── app.component.html
│ ├── app.component.spec.ts
│ ├── app.component.ts
│ └── app.module.ts
├── assets/
├── environments/
├── theme/
├── global.scss
├── index.html
├── karma.conf.js
├── main.ts
├── polyfills.ts
├── test.ts
├── tsconfig.app.json