Skip to content

Commit 6c50d58

Browse files
committed
ng-sample webpack update
1 parent 3e4f498 commit 6c50d58

File tree

8 files changed

+104
-73
lines changed

8 files changed

+104
-73
lines changed

Diff for: ng-sample/app/app.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import "globals";
2+
import "./modules";
3+
4+
global.registerModule("./main-page", function () { return require("./main-page"); });
5+
16
import * as profiling from "./profiling";
27
profiling.start('application-start');
38
import application = require("application");
49

510
//TODO: hide this in a separate module e.g. "angular-application"
6-
application.mainModule = "main-page";
11+
application.mainModule = "./main-page";
712
application.cssFile = "./app.css";
813
application.start();

Diff for: ng-sample/app/main-page.ts

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
import * as profiling from "./profiling";
22
import {topmost} from 'ui/frame';
33
import {TextView} from 'ui/text-view';
4+
import {Page} from 'ui/page';
45

56
import {nativeScriptBootstrap} from './nativescript-angular/application';
67
import {RendererTest} from './renderer-test';
7-
import {Benchmark} from './benchmark';
8+
//import {Benchmark} from './benchmark';
89

10+
export function createPage() {
11+
var page = new Page();
912

10-
//TODO: move to an angular init module/base page class
11-
export function pageLoaded(args) {
12-
profiling.stop('application-start');
13+
page.on('loaded', function() {
14+
profiling.stop('application-start');
15+
console.log('Page loaded');
1316

14-
var page = args.object;
15-
page.bindingContext = "";
17+
profiling.start('ng-bootstrap');
18+
console.log('BOOTSTRAPPING...');
19+
//nativeScriptBootstrap(Benchmark, []).then((appRef) => {
20+
nativeScriptBootstrap(RendererTest, []).then((appRef) => {
21+
profiling.stop('ng-bootstrap');
22+
console.log('ANGULAR BOOTSTRAP DONE.');
23+
}, (err) =>{
24+
console.log('ERROR BOOTSTRAPPING ANGULAR');
25+
let errorMessage = err.message + "\n\n" + err.stack;
26+
console.log(errorMessage);
1627

17-
profiling.start('ng-bootstrap');
18-
console.log('BOOTSTRAPPING...');
19-
//nativeScriptBootstrap(Benchmark, []).then((appRef) => {
20-
nativeScriptBootstrap(RendererTest, []).then((appRef) => {
21-
profiling.stop('ng-bootstrap');
22-
console.log('ANGULAR BOOTSTRAP DONE.');
23-
}, (err) =>{
24-
console.log('ERROR BOOTSTRAPPING ANGULAR');
25-
let errorMessage = err.message + "\n\n" + err.stack;
26-
console.log(errorMessage);
27-
28-
let view = new TextView();
29-
view.text = errorMessage;
30-
topmost().currentPage.content = view;
28+
let view = new TextView();
29+
view.text = errorMessage;
30+
topmost().currentPage.content = view;
31+
});
3132
});
33+
return page;
3234
}

Diff for: ng-sample/app/main-page.xml

-2
This file was deleted.

Diff for: ng-sample/app/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "tns-template-hello-world",
3-
"main": "app.js",
43
"version": "1.2.0",
54
"author": "Telerik <[email protected]>",
65
"description": "Nativescript hello-world project template",

Diff for: ng-sample/hooks/after-prepare/webpack.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var path = require("path");
2+
var shelljs = require("shelljs");
3+
4+
module.exports = function (logger, platformsData, projectData, hookArgs) {
5+
var platformData = platformsData.getPlatformData(hookArgs.platform.toLowerCase());
6+
var outDir = platformData.appDestinationDirectoryPath;
7+
console.log('outDir: ' + outDir);
8+
console.log('pwd: ' + shelljs.pwd());
9+
10+
return new Promise(function (resolve, reject) {
11+
return shelljs.exec("webpack", function(code, output) {
12+
if (code == 0) {
13+
//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"))
16+
17+
resolve();
18+
} else {
19+
console.log('webpack failed.');
20+
reject();
21+
}
22+
});
23+
});
24+
}

Diff for: ng-sample/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"grunt-ts": "5.0.0-beta.5",
4040
"nativescript-dev-typescript": "^0.2.2",
4141
"shelljs": "^0.5.3",
42-
"typescript": "^1.7.3"
42+
"typescript": "^1.7.3",
43+
"webpack": "^1.12.9"
4344
},
4445
"nativescript": {
4546
"id": "org.nativescript.ngsample",

Diff for: ng-sample/tsconfig.json

+37-36
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
{
2-
"compilerOptions": {
3-
"outDir": "app",
4-
"rootDir": "app",
5-
"module": "commonjs",
6-
"target": "es5",
7-
"inlineSourceMap": true,
8-
"experimentalDecorators": true,
9-
"removeComments": false,
10-
"emitDecoratorMetadata": true,
11-
"noEmitOnError": true
12-
},
13-
"files": [
14-
"app/app.ts",
15-
"app/benchmark.ts",
16-
"app/global.d.ts",
17-
"app/main-page.ts",
18-
"app/main-view-model.ts",
19-
"app/nativescript-angular/application.d.ts",
20-
"app/nativescript-angular/application.ts",
21-
"app/nativescript-angular/dom_adapter.ts",
22-
"app/nativescript-angular/element-registry.d.ts",
23-
"app/nativescript-angular/element-registry.ts",
24-
"app/nativescript-angular/polyfills/array.ts",
25-
"app/nativescript-angular/renderer.ts",
26-
"app/nativescript-angular/view_node.ts",
27-
"app/nativescript-angular/xhr.ts",
28-
"app/nativescript-angular/zone.ts",
29-
"app/nativescript-angular/zone_patch.ts",
30-
"app/profiling.ts",
31-
"app/renderer-test.ts",
32-
"node_modules/tns-core-modules/tns-core-modules.d.ts"
33-
],
34-
"filesGlob": [
35-
"node_modules/tns-core-modules/tns-core-modules.d.ts",
36-
"app/**/*.ts"
37-
]
2+
"compilerOptions": {
3+
"outDir": "app",
4+
"rootDir": "app",
5+
"module": "commonjs",
6+
"target": "es5",
7+
"inlineSourceMap": true,
8+
"experimentalDecorators": true,
9+
"removeComments": false,
10+
"emitDecoratorMetadata": true,
11+
"noEmitOnError": true
12+
},
13+
"files": [
14+
"app/app.ts",
15+
"app/benchmark.ts",
16+
"app/global.d.ts",
17+
"app/main-page.ts",
18+
"app/main-view-model.ts",
19+
"app/modules.ts",
20+
"app/nativescript-angular/application.d.ts",
21+
"app/nativescript-angular/application.ts",
22+
"app/nativescript-angular/dom_adapter.ts",
23+
"app/nativescript-angular/element-registry.d.ts",
24+
"app/nativescript-angular/element-registry.ts",
25+
"app/nativescript-angular/polyfills/array.ts",
26+
"app/nativescript-angular/renderer.ts",
27+
"app/nativescript-angular/view_node.ts",
28+
"app/nativescript-angular/xhr.ts",
29+
"app/nativescript-angular/zone.ts",
30+
"app/nativescript-angular/zone_patch.ts",
31+
"app/profiling.ts",
32+
"app/renderer-test.ts",
33+
"node_modules/tns-core-modules/tns-core-modules.d.ts"
34+
],
35+
"filesGlob": [
36+
"node_modules/tns-core-modules/tns-core-modules.d.ts",
37+
"app/**/*.ts"
38+
]
3839
}

Diff for: ng-sample/webpack.config.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var path = require("path");
2+
var webpack = require("webpack");
3+
24

35
module.exports = {
46
context: "./platforms/android/src/main/assets/app",
@@ -11,20 +13,13 @@ module.exports = {
1113
libraryTarget: "commonjs2",
1214
filename: "bundle.js"
1315
},
14-
//externals: {
15-
//"crypto": "crypto",
16-
//"process/browser.js": "process",
17-
//"module.js": "module"
18-
//},
1916
externals: [
2017
function(context, request, callback) {
21-
if (/\/module\.js$/.test(request))
22-
return callback(null, "var module");
23-
else if (/browserify/.test(request)) {
18+
if (/browserify|crypto/.test(request)) {
2419
return callback(null, "var {}");
25-
}
26-
else
20+
} else {
2721
callback();
22+
}
2823
}
2924
],
3025
resolve: {
@@ -37,5 +32,11 @@ module.exports = {
3732
module: {
3833
loaders: [
3934
]
40-
}
41-
}
35+
},
36+
plugins: [
37+
new webpack.DefinePlugin({
38+
global: 'global',
39+
__dirname: '__dirname'
40+
}),
41+
]
42+
};

0 commit comments

Comments
 (0)