Skip to content

Commit 5870849

Browse files
committed
Toggle bundling for ng-sample via the WEBPACK_BUILD env var.
1 parent 6befe17 commit 5870849

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

ng-sample/app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tns-template-hello-world",
3-
"main": "app.js",
3+
"main": "starter.js",
44
"version": "1.2.0",
55
"author": "Telerik <support@telerik.com>",
66
"description": "Nativescript hello-world project template",
@@ -22,4 +22,4 @@
2222
"url": "https://github.com/NativeScript/template-hello-world/issues"
2323
},
2424
"homepage": "https://github.com/NativeScript/template-hello-world"
25-
}
25+
}

ng-sample/app/starter.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//if (!global.timers) {
2+
//global.timers = new Map();
3+
//}
4+
5+
//function time() {
6+
//if (global.android) {
7+
//return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
8+
//}
9+
//else {
10+
//return CACurrentMediaTime() * 1000;
11+
//}
12+
//}
13+
14+
//var timerEntry = {
15+
//totalTime: 0,
16+
//count: 0,
17+
//currentStart: time()
18+
//};
19+
20+
//global.timers.set("application-start", timerEntry);
21+
22+
import "./app.js"

ng-sample/hooks/after-prepare/webpack.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@ var shelljs = require("shelljs");
44
module.exports = function (logger, platformsData, projectData, hookArgs) {
55
var platformData = platformsData.getPlatformData(hookArgs.platform.toLowerCase());
66
var outDir = platformData.appDestinationDirectoryPath;
7-
console.log('outDir: ' + outDir);
8-
console.log('pwd: ' + shelljs.pwd());
7+
8+
var gradleScript = path.join(outDir, "../../../", "build.gradle");
9+
shelljs.sed("-i", /aaptOptions.*\{[^\}]+\}/, "", gradleScript);
10+
11+
if (!process.env.WEBPACK_BUILD) {
12+
console.log('Not webpacking...');
13+
return;
14+
}
915

1016
return new Promise(function (resolve, reject) {
1117
return shelljs.exec("webpack", function(code, output) {
12-
if (code == 0) {
18+
if (code === 0) {
1319
//shelljs.rm("-rf", path.join(outDir, "app", "*"))
14-
shelljs.rm("-rf", path.join(outDir, "app", "main-page*"))
15-
shelljs.mv("bundle.js", path.join(outDir, "app", "index.js"))
20+
shelljs.rm("-rf", path.join(outDir, "app", "main-page*"));
21+
shelljs.mv("bundle.js", path.join(outDir, "app", "index.js"));
22+
23+
var packageJson = path.join(outDir, "app", "starter.js");
24+
shelljs.sed("-i", /require.*app\.js.*;/, "require('./index.js');", packageJson);
25+
26+
shelljs.sed("-i", /^android\s+\{/m, 'android {\n\taaptOptions { ignoreAssetsPattern "<dir>tns_modules" }', gradleScript);
1627

1728
resolve();
1829
} else {
@@ -21,4 +32,4 @@ module.exports = function (logger, platformsData, projectData, hookArgs) {
2132
}
2233
});
2334
});
24-
}
35+
};

ng-sample/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"app/nativescript-angular/zone_patch.ts",
3030
"app/profiling.ts",
3131
"app/renderer-test.ts",
32+
"app/starter.ts",
3233
"node_modules/tns-core-modules/tns-core-modules.d.ts"
3334
],
3435
"filesGlob": [

0 commit comments

Comments
 (0)