Skip to content

Commit 00e6233

Browse files
ikoevskarigor789
authored andcommitted
Proofreading Upgrade Guide (#206)
* Initial round of proofreading * Upgrade Guide: Proofreading complete
1 parent d33ca74 commit 00e6233

File tree

1 file changed

+65
-45
lines changed

1 file changed

+65
-45
lines changed
Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
---
22
title: Upgrade Guide
3-
contributors: [rigor789, jlooper]
3+
contributors: [rigor789, jlooper, ikoevska]
44
outdated: false
55
---
66

77
> Estimated time for the upgrade: **10-20 minutes**.
88
9-
If you scaffolded a NativeScript-Vue app using the 1.3.1 version of the Vue-CLI template, it's time to upgrade to the newest version, 2.0, and this guide will help you do that. The new template has a different folder structure from the older one:
9+
If you scaffolded a NativeScript-Vue app using the 1.3.1 version of the Vue-CLI template, it's time to upgrade to the newest 2.0 version. This guide will help you do that.
10+
11+
## Upgrade overivew
12+
13+
The new template has a different folder structure:
1014

1115
![New folder structure](/screenshots/old-new-folder-structure.png)
1216

13-
**Step 1**
17+
The simplified upgrade process involves:
18+
19+
1. Creating a new project from the updated template.
20+
1. Copying files from your old app into the new one.
21+
1. Rearranging and adding some files.
22+
23+
## Step 1: Create new app
1424

15-
Start by creating a new app using the Vue-CLI template.
25+
Use the Vue-CLI template to create a new app. Make sure to run the same preinstallation commands that you used for the old version. For example, if you installed Vuex in the CLI the first time, do it again now.
1626

17-
> **TIP:** Make sure you use the same preinstallation commands in this new project that you used when creating the older version; for example, if you installed Vuex in the CLI the first time, do it again now.
27+
Run the following command to create a new project from the Vue-CLI template.
1828

1929
```shell
2030
$ npm install -g @vue/cli @vue/cli-init
@@ -26,38 +36,49 @@ $ # or
2636
$ tns run ios --bundle
2737
```
2838

29-
The upgrade process involves copying files from your old app into the new project and then rearranging and adding some files.
39+
## Step 2: Replace `App_Resources`
3040

31-
**Step 2: Replace App Resources**
41+
First, copy your old app's `App_Resources` folder from `./template/app/`. Next, paste it into the new app's `app` folder. Make sure that you're replacing the new `App_Resources` folder.
3242

33-
Copy your old app's `App_Resources` folder from `./template/app/` and paste it into the new app's `app` folder, replacing its `App_Resources` folder.
43+
## Step 3: Merge the `src` and `app` folders
3444

35-
**Step 3: Merge `src` and `app` folders**
45+
Copy all the folders in `src` from your old app and paste them into the `app` folder in the new app.
3646

37-
Copy all the folders in `src` from your old app and paste them into the `app` folder in the new app. If you have custom fonts, move the `src/assets/fonts` folder to `app/fonts` in order to let NativeScript to load them automatically.
47+
If you have custom fonts, move the contents of the `src/assets/fonts` folder to `app/fonts`. This ensures that NativeScript will load your custom fonts automatically.
3848

39-
**Step 4: Edit `main.js`**
49+
## Step 4: Edit `main.js`
4050

41-
NativeScript 4.0 introduced a new Frame element, and introduced a way to change the root element of our applications, allowing for sharing common view elements across pages (navigations).
51+
Edit `main.js`'s Vue initialization block to resemble:
4252

43-
Prior to 4.0 the root element was a Frame, which was implicitly created by NativeScript when our application started.
53+
```js
54+
new Vue({
55+
render: h => h('frame', [h(HelloWorld)]),
56+
}).$start();
57+
```
4458

45-
With these changes, we are no longer able to automatically create a Frame and Page elements, so in 2.0.0 you are required to explicitly add these elements to your template.
59+
NativeScript 4.0 brings two major improvements:
4660

47-
To keep the previous behavior of having a single root Frame, you can change your root Vue instance to have a `<Frame>` and a `<Page>` element.
61+
* a new `<Frame>` element
62+
* a new way to change the root element of your app that lets you share common view elements across pages (navigations).
4863

49-
**Example**
64+
Before NativeScript 4.0, the root element was a `<Frame>` element which was implicitly created by NativeScript when the application started.
5065

51-
```js
52-
// in prior versions
66+
With the latest changes, `<Frame>` and `<Page>` elements are longer automatically created. So, in NativeScript-Vue 2.0.0, you need to explicitly add these elements to your template.
67+
68+
To keep the previous behavior of having a single root `<Frame>`, you can change your root Vue instance to have a `<Frame>` and a `<Page>` element.
69+
70+
**Example: Adding `<Frame>` and `<Page>` to the template**
71+
72+
```JavaScript
73+
// in older versions
5374
// this automatically created a Page
5475
new Vue({
5576
template: `<Label text="Hello world"/>`
5677
}).$start()
5778
```
5879

59-
```js
60-
// in 2.0.0
80+
```JavaScript
81+
// in NativeScript-Vue 2.0.0
6182
// the <Frame> and <Page> must exist in your template
6283
new Vue({
6384
template: `
@@ -70,7 +91,9 @@ new Vue({
7091
}).$start()
7192
```
7293

73-
This allows us to use a shared SideDrawer across different pages for example:
94+
This lets you use a shared element across different pages.
95+
96+
**Example: Using a shared `<SideDrawer>` element**
7497

7598
```js
7699
new Vue({
@@ -87,37 +110,31 @@ new Vue({
87110
}).$start()
88111
```
89112

90-
In its simplest form, however, edit `main.js`'s Vue initialization block to resemble:
91-
92-
```js
93-
new Vue({
94-
render: h => h('frame', [h(HelloWorld)]),
95-
}).$start();
96-
```
113+
## Step 5: Edit paths
97114

98-
**Step 5: Edit paths**
115+
Because the folder structure has changed, you need to edit the paths in your new app to point to your styles, fonts, and images.
99116

100-
Since the folder structure has changed, you need to edit the paths in your new app to point to your styles, fonts, and images.
117+
**Example: Changing image references**
101118

102-
In your components, if you have images from your old app referenced like this:
119+
In your old app, you are likely to have referenced images like this.
103120

104121
```HTML
105122
<Image v-if="surprise" src="~/images/NativeScript-Vue.png"/>
106123
```
107124

108-
Change the path:
125+
To ensure that NativeScript loads the images, change the path reference to the following.
109126

110127
```HTML
111128
<Image v-if="surprise" src="~/assets/images/NativeScript-Vue.png"/>
112129
```
113130

114-
**Step 6: Fix Manual Routing Props (if necessary)**
131+
## (If needed) Step 6: Fix manual routing props
115132

116-
If your app uses manual routing, please note that the syntax for passing props has changed.
133+
If your app uses manual routing, the syntax for passing props has changed. Note that this change might not be required in all projects.
117134

118-
Old syntax:
135+
Your old syntax is likely to look like this.
119136

120-
```js
137+
```JavaScript
121138
this.$navigateTo(NewPage, {
122139
transition: {},
123140
transitionIOS: {},
@@ -132,9 +149,9 @@ this.$navigateTo(NewPage, {
132149
});
133150
```
134151

135-
New syntax:
152+
To preserve the manual routing behavior in your new app, change your syntax to the following:
136153

137-
```js
154+
```JavaScript
138155
this.$navigateTo(NewPage, {
139156
transition: {},
140157
transitionIOS: {},
@@ -147,14 +164,15 @@ this.$navigateTo(NewPage, {
147164
});
148165
```
149166

167+
## Step 7: Align `package.json`
150168

151-
**Step 7: Align `package.json`**
169+
Copy the relevant values from your old app's root `package.json` file into the new app's root `package.json` file.
152170

153-
Copy the relevant values from your old app's root `package.json` file into the new app's root `package.json` file. This will most likely entail copying the `Dependencies:` block, but you might also need to realign the new app's app version and description at the top of `package.json`.
171+
You will likely need to copy the `Dependencies:` block and, in some cases, realign the new app's app version and description at the top of `package.json`.
154172

155-
**Step 8: Clean and run**
173+
## Step 8: Clean and run
156174

157-
At this point, it's a good idea to clean the new app's folders (if you have run it prior) and reinstall any dependencies.
175+
Run the following command to clean the new app's folders and reinstall any dependencies.
158176

159177
```shell
160178
$ cd <project-name>
@@ -165,9 +183,11 @@ $ # or
165183
$ tns run ios --bundle
166184
```
167185

168-
**Step 8 (Optional): Try HMR**
186+
## (Optional) Step 8: Try HMR
187+
188+
NativeScript now provides support for HMR (Hot Module Replacement). The latest version of NativeScript-Vue provides out-of-the-box HMR support as well but requires the NativeScript CLI.
169189

170-
Just recently nativescript received support for HMR (Hot Module Replacement). The latest version of NativeScript-Vue supports it out of the box, however you will need to install the latest (and greatest) version of the NativeScript CLI.
190+
Run the following command to get HMR support by installing the latest and greatest version of the NativeScript CLI.
171191

172192
```shell
173193
$ npm install -g nativescript@next
@@ -176,4 +196,4 @@ $ rm -rf platforms
176196
$ tns run android --hmr
177197
$ # or
178198
$ tns run ios --hmr
179-
```
199+
```

0 commit comments

Comments
 (0)