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.
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
Copy file name to clipboardExpand all lines: docs/core-concepts/android-runtime/advanced-topics/extend-application-activity.md
+29-2Lines changed: 29 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -78,14 +78,29 @@ The following steps are needed to create custom native `android.app.Application`
78
78
79
79
>This modification is required by the native platform; it basically tells Android that your custom `Application`classwill be used as the main entry point of the application.
80
80
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
+
81
96
## Extending Activity
82
97
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:
83
98
84
-
1.Create a newJavaScript file in your `app` folder - name it `activity.android.js`
99
+
1. Create a newJavaScript file in your `app` folder - name it `activity.android.js`
85
100
86
101
>Note the `*.android` suffix - we want this file packaged for Android only.
87
102
88
-
2.Declare the extend:
103
+
2. Declare the extend:
89
104
90
105
```javascript
91
106
const frame = require("ui/frame");
@@ -180,5 +195,17 @@ The core modules ship with a default `android.app.Activity` implementation, whic
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).
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
@@ -205,6 +205,10 @@ function logMessage(message) {
205
205
}
206
206
```
207
207
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
+
208
212
## Debugging Common Errors
209
213
210
214
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