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
{{ message }}
This repository was archived by the owner on Nov 17, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/core-concepts/project-structure.md
+21-11Lines changed: 21 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,7 @@ This is a secondary `package.json` file in which you can specify the entry point
90
90
{% endangular %}
91
91
92
92
93
-
#### Discarding JavaScript exceptions when called from native
93
+
#### Discarding JavaScript Exceptions Called from Native
94
94
95
95
Normally, an unhandled exception from JavaScript code called from a native API will crash the application showing the stack trace. If you want to prevent such crashes you can override this behavior using the `discardUncaughtJsExceptions` flag.
96
96
@@ -112,11 +112,11 @@ application.on(application.discardedErrorEvent, function (args) {
112
112
});
113
113
```
114
114
115
-
#### Android runtime configuration
115
+
#### Android Runtime Configuration
116
116
117
117
For desciption of the flags which are specific to the Android runtime see the [Android custom flags article]({% slug android-custom-flags %}).
118
118
119
-
#### iOS runtime configuration
119
+
#### iOS Runtime Configuration
120
120
121
121
For description of the flags which are specific to the iOS runtime see the [iOS custom flags article]({% slug ios-custom-flags %}).
122
122
@@ -126,13 +126,13 @@ The `App_Resources` folder contains the platform-specific resources of the appli
126
126
127
127
Additionally, you can modify the `App_Resources/iOS/build.xcconfig` or `App_Resources/Android/app.gradle` to add or remove additional build properties for the iOS and Android platforms, respectively.
128
128
129
-
## The **platforms**directory
129
+
## The **platforms**Directory
130
130
131
131
The `platforms` directory is created when you start a build or add a target platform to your project. The NativeScript tooling creates a new subdirectory with the respective platform name. These subdirectories have the platform-specific project structure required for native development with the native SDKs of the platform. When the project is prepared for build, the NativeScript tooling copies relevant content from the {% nativescript %}`app`{% endnativescript %}{% angular %}`src`{% endangular%} directory to the platform-specific subdirectory for each target platform.
132
132
133
133
> **IMPORTANT:** Avoid editing files located in the `platforms` subdirectories because the NativeScript CLI overrides them with the content of the {% nativescript %}`app`{% endnativescript %}{% angular %}`src`{% endangular%} directory during the `prepare <Platform>` process.
134
134
135
-
## The **package.json**file
135
+
## The **package.json**File
136
136
137
137
The main `package.json`, which is located in the root directory of the project, contains details about the application, its dependencies and other helpful information. You can set [common npm package.json properties](https://docs.npmjs.com/files/package.json) like `author`, `description` and `version`, or specify the npm packages and [NativeScript plugins]({% slug plugins-infrastructure %}) on which your app depends by modifying the `dependencies` and `devDependencies` attributes.
138
138
@@ -170,29 +170,30 @@ Here is an example of a basic main `package.json` file:
170
170
}
171
171
```
172
172
173
-
## The **hooks**directory
173
+
## The **hooks**Directory
174
174
175
175
The `hooks` folder exists only when the project depends on plugins that require a hook to function properly. Hooks are executable pieces of code or Node.js scripts that are used to alter or augment the behavior of an extendable NativeScript CLI command. For more information about hooks and how to use them in NativeScript, see [Extending the CLI](https://github.com/NativeScript/nativescript-cli/blob/master/extending-cli.md).
176
176
177
177
Some of the more common plugins that have hooks are `nativescript-dev-webpack`, `nativescript-dev-typescript` and `nativescript-dev-sass`.
178
178
179
-
## The **tsconfig.json**file
179
+
## The **tsconfig.json**File
180
180
181
181
The `tsconfig.json` file is present only in projects that use TypeScript. The file works as a guide during the [transpilation]({% slug transpilers %}) of TypeScript to JavaScript. You can fine-tune the transpilation process by configuring the various [compiler options](https://www.typescriptlang.org/docs/handbook/compiler-options.html). For more information about `tsconfig.json`, see the official [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
182
182
183
-
## The **nsconfig.json**file
183
+
## The **nsconfig.json**File
184
184
185
-
The `nsconfig.json` is an optional configuration file, located at the root project directory on the same level as the main `package.json` file. This file makes it possible for users to modify the structure of their application. The available configurations are `appPath`and `appResourcesPath`.
185
+
The `nsconfig.json` is an optional configuration file, located at the root project directory on the same level as the main `package.json` file. This file makes it possible for users to modify the structure of their application and to enable/disable the HMR developer experience. The available configurations are `appPath`, `appResourcesPath`, and `useLegacyWorkflow`.
186
186
187
-
Both paths must be relative to the project root (where the `package.json` file and `platforms` directory are located) in order everything to work as expected. If `appPath` is omitted, the CLI will assume the application files are located inside a folder called {% nativescript %}`app`{% endnativescript %}{% angular %}`src`{% endangular%} inside the project folder. If `appResourcesPath` is omitted, the CLI will assume that they are at their default location - a folder called `App_Resources` inside the folder containing the rest of the app files.
187
+
The paths (`appPath` and `appResourcesPath`) must be relative to the project root (where the `package.json` file and `platforms` directory are located) in order everything to work as expected. If `appPath` is omitted, the CLI will assume the application files are located inside a folder called {% nativescript %}`app`{% endnativescript %}{% angular %}`src`{% endangular%} inside the project folder. If `appResourcesPath` is omitted, the CLI will assume that they are at their default location - a folder called `App_Resources` inside the folder containing the rest of the app files.
188
188
189
189
> **Important:** To use an `nsconfig.json` file in your project, you must ensure that it meets the following requirements:
190
190
* NativeScript CLI >= 4.0.0
191
+
* The `useLegacyWorkflow` option requires NativeScript CLI >= 5.3.0
191
192
* Android Runtime >= 4.0.0
192
193
* nativescript-dev-sass >= 1.3.6 (if used in the application)
193
194
* nativescript-dev-webpack >= 0.10.1 (if used in the application)
194
195
195
-
### **nsconfig.json** examples
196
+
### **nsconfig.json**Path examples
196
197
197
198
Let's assume the project is located at `/d/work/myApplication`.
198
199
@@ -219,3 +220,12 @@ Let's assume the project is located at `/d/work/myApplication`.
219
220
"appResourcesPath": "resources"
220
221
}
221
222
```
223
+
224
+
### **nsconfig.json** enabling HMR example
225
+
226
+
Enable the HMR developer experience by default. By setting `useLegacyWorkflow` to `false`, you will enable the HMR by default (no need to pass additional flags to have HMR). When omitted, the default value is` true` (default livesync experience without the enhanced HMR).
Copy file name to clipboardExpand all lines: docs/performance-optimizations/bundling-with-webpack.md
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,10 @@ Comparison chart for the HMR capabilities versus no-HMR versus no Webpack (pure
137
137
138
138
> Note: version 5.2 applies changes in application styles at runtime on the current page, thereby it avoids page reloading/navigation and preserves the application state and navigation history.
139
139
140
+
### Enabling HMR by Default
141
+
142
+
With NativeScript 5.3 and above the HMR (Hot Module Replacement) can be enabled by default (no need to pass `--hmr` flag). Achieve the above via the `nsconfig.json` file and the `useLegacyWorkflow` property set to `false.` Refer to the [CLI basics article](/start/cli-basics#using-run-with-hmr-by-default) for detailed instruction on this feature.
143
+
140
144
### Publishing Application
141
145
142
146
A bundled version of the application for Android can be built in release with this script:
Copy file name to clipboardExpand all lines: docs/start/cli-basics.md
+55Lines changed: 55 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,7 @@ Once your NativeScript mobile project is created, you can start the application
61
61
62
62
- Using a local build via the `run` command. This option allows you to experience the full developer experience (building and deploying on local emulators and devices). See the [full setup section](#full-setup-using-run) for details.
63
63
64
+
64
65
### Quick Setup Using PREVIEW
65
66
66
67
> **NOTE**: To complete this section you must finish the NativeScript [CLI quick setup]({% slug quick-start %}).
@@ -238,6 +239,60 @@ The `run` command will again take a few seconds, as the NativeScript CLI will be
238
239
239
240
Now that you have a full setup in place for developing your apps let’s look at a few additional things you can do.
240
241
242
+
### Using RUN with HMR
243
+
244
+
The developer experience significantly improves by using the [HMR (Hot Module Replacement)](/performance-optimizations/bundling-with-webpack#hot-module-replacement) feature introduced in NativeScript 5. The option requires **nativescript-dev-webpack** plugin (enabled by default in all NativeScript 5.x.x templates) and behind the scene creates Webpack bundle with the enhancement of Hot Module Replacement developer experience.
245
+
246
+
To enable HMR during your development pass the `--hmr` flag (you can emit the `--bundle` which is automatically triggered).
247
+
248
+
For example:
249
+
```Shell
250
+
tns run --hmr
251
+
```
252
+
253
+
### Using RUN with HMR by default
254
+
255
+
With NativeScript 5.3 and above, the CLI provides the option to enable the HMR developer experience by default. This can be achieved by creating a `nsconfig.json` (see the detailed article about [nsconfig file and options](/core-concepts/project-structure#nsconfigjson-examples)) and passing the `useLegacyWorkflow` boolean property.
256
+
257
+
For example:
258
+
259
+
_nsconfig.json_
260
+
```JSON
261
+
{
262
+
"useLegacyWorkflow": false
263
+
}
264
+
```
265
+
266
+
Then execute the RUN command, and the HMR is enabled.
267
+
```Shell
268
+
tns run
269
+
```
270
+
271
+
-`useLegacyWorkflow` is set to `false`: The option disables the default livesync, in favor of the enhanced HMR (no need to pass additional flag).
272
+
-`useLegacyWorkflow` is set to `true`(default value): The option enables the default livesync experience (explicit enabling of HMR via `--hmr` flag is still possible).
273
+
274
+
275
+
> **Note:** There are conceptual differences when the `useLegacyWorkflow` is used in **debug** build versus when used in **release** builds. When the flag is enabled against a debug build, the extended HMR experience is enabled. However, in cases where the `--release` flag is passed (release build) then only the `--bundle` is executed in the background (No HMR). The reason for this is to avoid bringing additional HMR logic and files into production. For details about the differences between Webpack livesync and HMR refer to [the comparative table](/performance-optimizations/bundling-with-webpack#hot-module-replacement).
276
+
277
+
#### Enhancement flags for useLegacyWorkflow
278
+
279
+
The flags `--no-hmr` and `--no-bundle` can be used once the `useLegacyWorkflow` option is set to `false`.
280
+
281
+
In case, when you have enabled the default HMR via the `useLegacyWorkflow` option, but you need to test without using HMR you can pass the `--no-hmr` flag to disable the feature for the current build.
282
+
283
+
For example:
284
+
```Shell
285
+
tns run --no-hmr
286
+
```
287
+
Using `--no-hmr` will effectively provide the default livesync experience with Webpack bundle.
288
+
289
+
In case, when you have enabled the default HMR via the `useLegacyWorkflow` option, but you want to disable both HMR and Webpack bundling, you can pass `--no-bundle` flag.
290
+
291
+
For example:
292
+
```Shell
293
+
tns run --no-bundle
294
+
```
295
+
241
296
### Next steps
242
297
243
298
Now that you have a preview workflow set up check out our **Build a Full App** tutorials in NativeScript Playground. If you prefer working in a CLI environment, you can download your tutorial project from Playground and complete the tutorial locally using the `tns preview` command.
0 commit comments