You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Estimated time for the upgrade: **10-20 minutes**.
8
8
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:
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
14
24
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.
16
26
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.
18
28
19
29
```shell
20
30
$ npm install -g @vue/cli @vue/cli-init
@@ -26,38 +36,49 @@ $ # or
26
36
$ tns run ios --bundle
27
37
```
28
38
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`
30
40
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.
32
42
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
34
44
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.
36
46
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.
38
48
39
-
**Step 4: Edit `main.js`**
49
+
## Step 4: Edit `main.js`
40
50
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:
42
52
43
-
Prior to 4.0 the root element was a Frame, which was implicitly created by NativeScript when our application started.
53
+
```js
54
+
newVue({
55
+
render:h=>h('frame', [h(HelloWorld)]),
56
+
}).$start();
57
+
```
44
58
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:
46
60
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).
48
63
49
-
**Example**
64
+
Before NativeScript 4.0, the root element was a `<Frame>` element which was implicitly created by NativeScript when the application started.
50
65
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
53
74
// this automatically created a Page
54
75
newVue({
55
76
template:`<Label text="Hello world"/>`
56
77
}).$start()
57
78
```
58
79
59
-
```js
60
-
// in 2.0.0
80
+
```JavaScript
81
+
// in NativeScript-Vue 2.0.0
61
82
// the <Frame> and <Page> must exist in your template
62
83
newVue({
63
84
template:`
@@ -70,7 +91,9 @@ new Vue({
70
91
}).$start()
71
92
```
72
93
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**
74
97
75
98
```js
76
99
newVue({
@@ -87,37 +110,31 @@ new Vue({
87
110
}).$start()
88
111
```
89
112
90
-
In its simplest form, however, edit `main.js`'s Vue initialization block to resemble:
91
-
92
-
```js
93
-
newVue({
94
-
render:h=>h('frame', [h(HelloWorld)]),
95
-
}).$start();
96
-
```
113
+
## Step 5: Edit paths
97
114
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.
99
116
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**
101
118
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.
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.
117
134
118
-
Old syntax:
135
+
Your old syntax is likely to look like this.
119
136
120
-
```js
137
+
```JavaScript
121
138
this.$navigateTo(NewPage, {
122
139
transition: {},
123
140
transitionIOS: {},
@@ -132,9 +149,9 @@ this.$navigateTo(NewPage, {
132
149
});
133
150
```
134
151
135
-
New syntax:
152
+
To preserve the manual routing behavior in your new app, change your syntax to the following:
136
153
137
-
```js
154
+
```JavaScript
138
155
this.$navigateTo(NewPage, {
139
156
transition: {},
140
157
transitionIOS: {},
@@ -147,14 +164,15 @@ this.$navigateTo(NewPage, {
147
164
});
148
165
```
149
166
167
+
## Step 7: Align `package.json`
150
168
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.
152
170
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`.
154
172
155
-
**Step 8: Clean and run**
173
+
## Step 8: Clean and run
156
174
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.
158
176
159
177
```shell
160
178
$ cd<project-name>
@@ -165,9 +183,11 @@ $ # or
165
183
$ tns run ios --bundle
166
184
```
167
185
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.
169
189
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.
0 commit comments