Skip to content

Commit e8b457f

Browse files
sis0k0Alexander Vakrilov
authored andcommitted
feat: Add AoT compilation with webpack (#215)
Added AoT/Webpack support and updates it to NativeScript 2.5 Fixes #213
1 parent b36fdac commit e8b457f

18 files changed

+320
-40
lines changed

app/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import url("~/platform.css");
1+
@import url("./platform.css");
22

33
Page {
44
font-size: 15;

app/app.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
2-
import { NgModule } from "@angular/core";
2+
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
33
import { NativeScriptHttpModule } from "nativescript-angular/http";
44
import { NativeScriptRouterModule } from "nativescript-angular/router";
55

@@ -29,6 +29,7 @@ setStatusBarColors();
2929
declarations: [
3030
AppComponent,
3131
],
32-
bootstrap: [AppComponent]
32+
bootstrap: [AppComponent],
33+
schemas: [NO_ERRORS_SCHEMA]
3334
})
3435
export class AppModule { }

app/groceries/groceries.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { LoginService, alert } from "../shared";
1212

1313
@Component({
1414
selector: "gr-groceries",
15-
templateUrl: "groceries/groceries.component.html",
16-
styleUrls: ["groceries/groceries-common.css", "groceries/groceries.component.css"],
15+
moduleId: module.id,
16+
templateUrl: "./groceries.component.html",
17+
styleUrls: ["./groceries-common.css", "./groceries.component.css"],
1718
providers: [GroceryService]
1819
})
1920
export class GroceriesComponent implements OnInit {

app/groceries/groceries.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { NativeScriptModule } from "nativescript-angular/platform";
1+
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
22
import { NativeScriptFormsModule } from "nativescript-angular/forms";
3-
import { NgModule } from "@angular/core";
3+
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
44
import { groceriesRouting } from "./groceries.routing";
55
import { GroceriesComponent } from "./groceries.component";
66
import { GroceryListComponent } from "./grocery-list/grocery-list.component";
@@ -16,6 +16,7 @@ import { ItemStatusPipe } from "./grocery-list/item-status.pipe";
1616
GroceriesComponent,
1717
GroceryListComponent,
1818
ItemStatusPipe
19-
]
19+
],
20+
schemas: [NO_ERRORS_SCHEMA]
2021
})
2122
export class GroceriesModule {}

app/groceries/grocery-list/grocery-list.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ declare var UIColor: any;
88

99
@Component({
1010
selector: "gr-grocery-list",
11-
templateUrl: "groceries/grocery-list/grocery-list.component.html",
12-
styleUrls: ["groceries/grocery-list/grocery-list.component.css"],
11+
moduleId: module.id,
12+
templateUrl: "./grocery-list.component.html",
13+
styleUrls: ["./grocery-list.component.css"],
1314
changeDetection: ChangeDetectionStrategy.OnPush
1415
})
1516
export class GroceryListComponent {

app/login/login.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { alert, LoginService, User } from "../shared";
1212

1313
@Component({
1414
selector: "gr-login",
15-
templateUrl: "login/login.component.html",
16-
styleUrls: ["login/login-common.css", "login/login.component.css"],
15+
moduleId: module.id,
16+
templateUrl: "./login.component.html",
17+
styleUrls: ["./login-common.css", "./login.component.css"],
1718
})
1819
export class LoginComponent implements OnInit {
1920
user: User;

app/login/login.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { NativeScriptModule } from "nativescript-angular/platform";
1+
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
22
import { NativeScriptFormsModule } from "nativescript-angular/forms";
3-
import { NgModule } from "@angular/core";
3+
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
44

55
import { loginRouting } from "./login.routing";
66
import { LoginComponent } from "./login.component";
@@ -13,6 +13,7 @@ import { LoginComponent } from "./login.component";
1313
],
1414
declarations: [
1515
LoginComponent
16-
]
16+
],
17+
schemas: [NO_ERRORS_SCHEMA]
1718
})
1819
export class LoginModule { }

app/main.aot.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// this import should be first in order to load some required settings (like globals and reflect-metadata)
2+
import { platformNativeScript } from "nativescript-angular/platform-static";
3+
4+
import { AppModuleNgFactory } from "./app.module.ngfactory";
5+
6+
platformNativeScript().bootstrapModuleFactory(AppModuleNgFactory);

app/vendor-platform.android.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Resolve JavaScript classes that extend a Java class, and need to resolve
2+
// their JavaScript module from a bundled script. For example:
3+
// NativeScriptApplication, NativeScriptActivity, etc.
4+
//
5+
// This module gets bundled together with the rest of the app code and the
6+
// `require` calls get resolved to the correct bundling import call.
7+
//
8+
// At runtime the module gets loaded *before* the rest of the app code, so code
9+
// placed here needs to be careful about its dependencies.
10+
11+
require("application");
12+
require("ui/frame");
13+
require("ui/frame/activity");
14+
15+
if (global.TNS_WEBPACK) {
16+
global.__requireOverride = function (name, dir) {
17+
if (name === "./tns_modules/application/application.js") {
18+
return require("application");
19+
} else if (name === "./tns_modules/ui/frame/frame.js") {
20+
return require("ui/frame");
21+
} else if (name === "./tns_modules/ui/frame/activity.js") {
22+
return require("ui/frame/activity");
23+
}
24+
};
25+
}

app/vendor-platform.ios.ts

Whitespace-only changes.

app/vendor.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require("./vendor-platform");
2+
3+
require("reflect-metadata");
4+
require("@angular/platform-browser");
5+
require("@angular/core");
6+
require("@angular/common");
7+
require("@angular/forms");
8+
require("@angular/http");
9+
require("@angular/router");
10+
11+
require("nativescript-angular/platform-static");
12+
require("nativescript-angular/forms");
13+
require("nativescript-angular/router");

package.json

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,72 @@
1818
"nativescript": {
1919
"id": "org.nativescript.groceries",
2020
"tns-android": {
21-
"version": "2.4.1"
21+
"version": "2.5.0"
2222
},
2323
"tns-ios": {
24-
"version": "2.4.0"
24+
"version": "2.5.0"
2525
}
2626
},
2727
"scripts": {
28-
"tslint": "tslint \"app/**/*.ts\""
28+
"tslint": "tslint \"app/**/*.ts\"",
29+
"clean-android": "tns clean-app android",
30+
"clean-ios": "tns clean-app ios",
31+
"prewebpack-android": "npm run clean-android",
32+
"prewebpack-ios": "npm run clean-ios",
33+
"webpack-android": "webpack --config=webpack.android.js --progress",
34+
"webpack-ios": "webpack --config=webpack.ios.js --progress",
35+
"prestart-android-bundle": "npm run webpack-android",
36+
"prestart-ios-bundle": "npm run webpack-ios",
37+
"start-android-bundle": "tns run android --bundle --disable-npm-install",
38+
"start-ios-bundle": "tns run ios --bundle --disable-npm-install",
39+
"prebuild-android-bundle": "npm run webpack-android",
40+
"prebuild-ios-bundle": "npm run webpack-ios",
41+
"build-android-bundle": "tns build android --bundle --disable-npm-install",
42+
"build-ios-bundle": "tns build ios --bundle --disable-npm-install"
2943
},
3044
"dependencies": {
31-
"@angular/common": "~2.3.1",
32-
"@angular/compiler": "~2.3.1",
33-
"@angular/core": "~2.3.1",
34-
"@angular/forms": "~2.3.1",
35-
"@angular/http": "~2.3.1",
36-
"@angular/platform-browser": "~2.3.1",
37-
"@angular/platform-browser-dynamic": "~2.3.1",
38-
"@angular/router": "~3.3.1",
45+
"@angular/common": "2.4.5",
46+
"@angular/compiler": "2.4.5",
47+
"@angular/core": "2.4.5",
48+
"@angular/forms": "2.4.5",
49+
"@angular/http": "2.4.5",
50+
"@angular/platform-browser": "2.4.5",
51+
"@angular/platform-browser-dynamic": "2.4.5",
52+
"@angular/router": "3.4.5",
3953
"email-validator": "1.0.4",
40-
"nativescript-angular": "1.3.0",
54+
"nativescript-angular": "1.4.0",
4155
"nativescript-iqkeyboardmanager": "1.0.1",
42-
"nativescript-social-share": "1.3.1",
56+
"nativescript-social-share": "~1.3.2",
4357
"nativescript-unit-test-runner": "^0.3.3",
4458
"reflect-metadata": "^0.1.8",
45-
"rxjs": "5.0.0-rc.4",
46-
"tns-core-modules": "^2.4.2"
59+
"rxjs": "~5.0.1",
60+
"tns-core-modules": "2.5.0"
4761
},
4862
"devDependencies": {
49-
"zone.js": "~0.7.2",
63+
"@angular/compiler-cli": "2.4.5",
5064
"babel-traverse": "6.8.0",
5165
"babel-types": "6.8.1",
5266
"babylon": "6.8.0",
53-
"codelyzer": "0.0.28",
67+
"codelyzer": "2.0.0-beta.4",
68+
"copy-webpack-plugin": "~3.0.1",
69+
"extract-text-webpack-plugin": "~2.0.0-beta.4",
5470
"filewalker": "0.1.2",
5571
"jasmine-core": "^2.4.1",
5672
"karma": "^1.2.0",
5773
"karma-jasmine": "^1.0.2",
5874
"karma-nativescript-launcher": "^0.4.0",
5975
"lazy": "1.0.11",
6076
"nativescript-dev-typescript": "^0.3.2",
61-
"tslint": "^3.14.0",
62-
"typescript": "~2.0.10"
77+
"nativescript-dev-webpack": "^0.3.1",
78+
"raw-loader": "~0.5.1",
79+
"resolve-url-loader": "~1.6.0",
80+
"tslint": "^4.0.0",
81+
"typescript": "^2.1.0",
82+
"webpack-sources": "~0.1.3",
83+
"zone.js": "~0.7.2",
84+
"nativescript-css-loader": "~0.26.0",
85+
"htmlparser2": "^3.9.2",
86+
"webpack": "2.2.0",
87+
"@ngtools/webpack": "1.2.4"
6388
}
6489
}

tsconfig.aot.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "es2015",
5+
"moduleResolution": "node",
6+
"sourceMap": true,
7+
"emitDecoratorMetadata": true,
8+
"experimentalDecorators": true,
9+
"removeComments": false,
10+
"noImplicitAny": false,
11+
"suppressImplicitAnyIndexErrors": true,
12+
"types": [],
13+
"baseUrl": ".",
14+
"paths": {
15+
"ui/*": ["node_modules/tns-core-modules/ui/*"],
16+
"platform": ["node_modules/tns-core-modules/platform"],
17+
"image-source": ["node_modules/tns-core-modules/image-source"],
18+
"xml": ["node_modules/tns-core-modules/xml"],
19+
"xhr": ["node_modules/tns-core-modules/xhr"],
20+
"text": ["node_modules/tns-core-modules/text"],
21+
"data": ["node_modules/tns-core-modules/data"],
22+
"fetch": ["node_modules/tns-core-modules/fetch"],
23+
"trace": ["node_modules/tns-core-modules/trace"],
24+
"fps-meter": ["node_modules/tns-core-modules/fps-meter"],
25+
"color": ["node_modules/tns-core-modules/color"],
26+
"application-settings": ["node_modules/tns-core-modules/application-settings"],
27+
"http": ["node_modules/tns-core-modules/http"],
28+
"camera": ["node_modules/tns-core-modules/camera"],
29+
"console": ["node_modules/tns-core-modules/console"],
30+
"timer": ["node_modules/tns-core-modules/timer"],
31+
"utils": ["node_modules/tns-core-modules/utils"],
32+
"location": ["node_modules/tns-core-modules/location"],
33+
"file-system": ["node_modules/tns-core-modules/file-system"],
34+
"application": ["node_modules/tns-core-modules/application"],
35+
"image-asset": ["node_modules/tns-core-modules/image-asset"],
36+
"connectivity": ["node_modules/tns-core-modules/connectivity"],
37+
"globals": ["node_modules/tns-core-modules/globals"]
38+
39+
}
40+
},
41+
"exclude": [
42+
"node_modules",
43+
"platforms"
44+
],
45+
"angularCompilerOptions": {
46+
"skipMetadataEmit": true,
47+
"genDir": "./"
48+
}
49+
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"exclude": [
1111
"node_modules",
12-
"platforms"
12+
"platforms",
13+
"**/*.aot.ts"
1314
]
1415
}

webpack.android.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var makeConfig = require("./webpack.common");
2+
module.exports = makeConfig("android");

0 commit comments

Comments
 (0)