Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit 14224dd

Browse files
author
Vasil Chimev
authored
docs(webpack): update custom application and activity article (#1254)
* docs(webpack): add custom application and activity section * docs(webpack): minor tweaks * docs(webpack): update extend article Move custom application and activity webpack configuration information to the `extend-application-activity.md` article. * docs(webpack): minor tweaks
1 parent 5ac3a3d commit 14224dd

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

docs/core-concepts/android-runtime/advanced-topics/extend-application-activity.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,29 @@ The following steps are needed to create custom native `android.app.Application`
7878

7979
>This modification is required by the native platform; it basically tells Android that your custom `Application` class will be used as the main entry point of the application.
8080

81+
4. In order to build the app with [webpack](../../../performance-optimizations/bundling-with-webpack.md), the extended Android application should be added as an [entry](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/demo/AngularApp/webpack.config.js#L71) to the `webpack.config.js` file.
82+
83+
```javascript
84+
entry: {
85+
bundle: entryPath,
86+
application: "./application.android",
87+
},
88+
```
89+
90+
In this way, the source code of [`application.android.ts`](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/demo/AngularApp/app/application.android.ts) is bundled separately as `application.js` file which is loaded from the native `Application.java` class on launch.
91+
92+
The `bundle.js` and `vendor.js` files are not loaded early enough in the application launch. That's why the logic in `application.android.ts` is needed to be bundled separately in order to be loaded as early as needed in the application lifecycle.
93+
94+
> Note: This approach won't work if `aplication.android.ts` requires external modules.
95+
8196
## Extending Activity
8297
The core modules ship with a default `android.app.Activity` implementation, which ensures they alone are sufficient to bootstrap an empty NativeScript application, without forcing users to declare their custom `Activity` in every project. When needed, however, users may still specify custom `Activity` implementation and use it to bootstrap the application. The following code demonstrates how this can be done:
8398

84-
1. Create a new JavaScript file in your `app` folder - name it `activity.android.js`
99+
1. Create a new JavaScript file in your `app` folder - name it `activity.android.js`
85100

86101
>Note the `*.android` suffix - we want this file packaged for Android only.
87102

88-
2. Declare the extend:
103+
2. Declare the extend:
89104

90105
```javascript
91106
const frame = require("ui/frame");
@@ -180,5 +195,17 @@ The core modules ship with a default `android.app.Activity` implementation, whic
180195
android:configChanges="keyboardHidden|orientation|screenSize">
181196
```
182197

198+
4. In order to build the app with [webpack](../../../performance-optimizations/bundling-with-webpack.md), the absolute path to the file where the Android activity is extended should be added to the [`appComponents`](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/demo/AngularApp/webpack.config.js#L19) array.
199+
200+
```javascript
201+
const appComponents = [
202+
"tns-core-modules/ui/frame",
203+
"tns-core-modules/ui/frame/activity",
204+
resolve(__dirname, "app/activity.android.ts"),
205+
];
206+
```
207+
208+
In this way and with the default config, these components [get](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/demo/AngularApp/webpack.config.js#L109-L116) in the common *vendor.js* chunk and are required by the [`android-app-components-loader`](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/demo/AngularApp/webpack.config.js#L146-L149).
209+
183210
## See Also
184211
* [How Extend Works](../generator/extend-class-interface.md)

docs/performance-optimizations/bundling-with-webpack.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ function logMessage(message) {
205205
}
206206
```
207207

208+
## Custom Application and Activity
209+
210+
NativeScript provides a way to create custom `android.app.Application` and `android.app.Activity` implementations. Please, refer to [this](../core-concepts/android-runtime/advanced-topics/extend-application-activity) documentation article for a detail description of how to achieve these as well as how to configure and bundle such a project.
211+
208212
## Debugging Common Errors
209213

210214
Webpack bundling can fail for different reasons. It sometimes fails to resolve certain modules, or it generates code that breaks at runtime. We'll try to cover a few common failure reasons with steps to resolve them in the following sections.

0 commit comments

Comments
 (0)