From 1205173948c4dd0b3e15a634f1cbef52b9a3fb61 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Wed, 6 Apr 2016 14:20:43 +0300 Subject: [PATCH 1/3] Use the nativescript-dev-webpack plugin. --- .gitignore | 1 + ng-sample/app/package.json | 2 + .../after-prepare/nativescript-dev-webpack.js | 1 + ng-sample/hooks/after-prepare/webpack.js | 43 --------------- ng-sample/package.json | 7 ++- ng-sample/tsconfig.json | 1 + ng-sample/webpack.config.js | 53 ++----------------- 7 files changed, 12 insertions(+), 96 deletions(-) create mode 100644 ng-sample/hooks/after-prepare/nativescript-dev-webpack.js delete mode 100644 ng-sample/hooks/after-prepare/webpack.js diff --git a/.gitignore b/.gitignore index bbc9ed3d0..6941663bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +nativescript-angular*.tgz bin/dist node_modules tags diff --git a/ng-sample/app/package.json b/ng-sample/app/package.json index 04b138175..afcb31a83 100644 --- a/ng-sample/app/package.json +++ b/ng-sample/app/package.json @@ -1,6 +1,8 @@ { "name": "tns-template-hello-world", "main": "starter.js", + "bundleMain": "app.js", + "bundleOutput": "bundle.js", "version": "1.2.0", "author": "Telerik ", "description": "Nativescript hello-world project template", diff --git a/ng-sample/hooks/after-prepare/nativescript-dev-webpack.js b/ng-sample/hooks/after-prepare/nativescript-dev-webpack.js new file mode 100644 index 000000000..6e2939411 --- /dev/null +++ b/ng-sample/hooks/after-prepare/nativescript-dev-webpack.js @@ -0,0 +1 @@ +module.exports = require("nativescript-dev-webpack/after-prepare-hook.js"); diff --git a/ng-sample/hooks/after-prepare/webpack.js b/ng-sample/hooks/after-prepare/webpack.js deleted file mode 100644 index 9d33c139c..000000000 --- a/ng-sample/hooks/after-prepare/webpack.js +++ /dev/null @@ -1,43 +0,0 @@ -var path = require("path"); -var shelljs = require("shelljs"); - -module.exports = function (logger, platformsData, projectData, hookArgs) { - var platformData = platformsData.getPlatformData(hookArgs.platform.toLowerCase()); - var outDir = platformData.appDestinationDirectoryPath; - process.env.PROJECT_DIR = outDir; - - var gradleScript = path.join(outDir, "../../../", "build.gradle"); - var hasGradle = shelljs.test("-e", gradleScript); - - if (hasGradle) { - //clean up any previous settings - shelljs.sed("-i", /aaptOptions.*\{[^\}]+\}/, "", gradleScript); - } - - if (!process.env.WEBPACK_BUILD) { - console.log('Not webpacking...'); - return; - } - - return new Promise(function (resolve, reject) { - return shelljs.exec("webpack", function(code, output) { - if (code === 0) { - //shelljs.rm("-rf", path.join(outDir, "app", "*")) - shelljs.rm("-rf", path.join(outDir, "app", "main-page*")); - shelljs.mv("bundle.js", path.join(outDir, "app", "index.js")); - - var packageJson = path.join(outDir, "app", "starter.js"); - shelljs.sed("-i", /require.*app\.js.*;/, "require('./index.js');", packageJson); - - if (hasGradle) { - shelljs.sed("-i", /^android\s+\{/m, 'android {\n\taaptOptions { ignoreAssetsPattern "tns_modules" }', gradleScript); - } - - resolve(); - } else { - console.log('webpack failed.'); - reject(); - } - }); - }); -}; diff --git a/ng-sample/package.json b/ng-sample/package.json index eea477e00..b5ec8f805 100644 --- a/ng-sample/package.json +++ b/ng-sample/package.json @@ -41,9 +41,8 @@ "grunt-shell": "1.1.2", "grunt-ts": "5.0.0-beta.5", "nativescript-dev-typescript": "^0.3.1", - "shelljs": "^0.5.3", - "typescript": "1.8.2", - "webpack": "^1.12.9" + "nativescript-dev-webpack": "0.0.7", + "typescript": "1.8.2" }, "nativescript": { "id": "org.nativescript.ngsample", @@ -51,4 +50,4 @@ "version": "1.7.1" } } -} +} \ No newline at end of file diff --git a/ng-sample/tsconfig.json b/ng-sample/tsconfig.json index 871abe41b..f7941352f 100644 --- a/ng-sample/tsconfig.json +++ b/ng-sample/tsconfig.json @@ -8,6 +8,7 @@ "experimentalDecorators": true, "removeComments": false, "emitDecoratorMetadata": true, + "noImplicitUseStrict": true, "noEmitOnError": true }, "exclude": [ diff --git a/ng-sample/webpack.config.js b/ng-sample/webpack.config.js index 7556cf9c5..fc192736f 100644 --- a/ng-sample/webpack.config.js +++ b/ng-sample/webpack.config.js @@ -1,50 +1,5 @@ -var path = require("path"); -var webpack = require("webpack"); +var bundler = require("nativescript-dev-webpack"); - -console.log('PROJECT_DIR: ' + process.env.PROJECT_DIR); - -module.exports = { - //context: "./platforms/android/src/main/assets/app", - context: process.env.PROJECT_DIR, - entry: { - app: "./app", - }, - output: { - path: __dirname, - pathinfo: true, - libraryTarget: "commonjs2", - filename: "bundle.js" - }, - externals: [ - function(context, request, callback) { - if (/browserify|crypto/.test(request)) { - return callback(null, "var {}"); - } else { - callback(); - } - } - ], - resolve: { - extensions: ["", ".js"], - packageMains: ["main"], - modulesDirectories: [ - "tns_modules", - ] - }, - module: { - loaders: [ - ] - }, - plugins: [ - new webpack.DefinePlugin({ - global: 'global', - __dirname: '__dirname' - }), - //new webpack.optimize.UglifyJsPlugin({ - //compress: { - //warnings: true - //} - //}) - ] -}; +module.exports = bundler.getConfig({ + // TODO: add project-specific webpack settings here... +}); From 9613a7eae98ff791f49568c1ce5b44417c553626 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Wed, 6 Apr 2016 14:21:32 +0300 Subject: [PATCH 2/3] Update zone.js imports and tns-core-modules dependency (needed for zone.js) --- package.json | 2 +- src/nativescript-angular/application.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 0c8062c7d..a26ca453f 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "typescript": "1.8.2" }, "peerDependencies": { - "tns-core-modules": ">=2.0.0 || >=2.0.0-2016 || >=2.0.0-angular-2" + "tns-core-modules": ">=2.0.0 || >=2.0.0-2016 || >=2.0.0-angular-3" }, "nativescript": {} } diff --git a/src/nativescript-angular/application.ts b/src/nativescript-angular/application.ts index 4fa8591c3..c22ad1b01 100644 --- a/src/nativescript-angular/application.ts +++ b/src/nativescript-angular/application.ts @@ -1,6 +1,3 @@ -//Import globals before the zone, so the latter can patch the global functions -import 'globals'; - //prevent a crash in zone patches. pretend we're node.js global.process = {}; const oldToString = Object.prototype.toString; @@ -10,6 +7,10 @@ Object.prototype.toString = function() { import "zone.js/dist/zone.js" Object.prototype.toString = oldToString; delete global.process; +// +//Import globals after the zone, so the latter can't patch everything there. +//The patchables should already be zone-aware already. +import 'globals'; import 'reflect-metadata'; import './polyfills/array'; From c8e7325e93e6110099271ab8e57ffad2ee829f9e Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Wed, 6 Apr 2016 14:21:41 +0300 Subject: [PATCH 3/3] Version bump: 0.0.40 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a26ca453f..fc442005f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-angular", - "version": "0.0.39", + "version": "0.0.40", "description": "", "homepage": "http://www.telerik.com", "bugs": "http://www.telerik.com",