Skip to content

fix: update demo to work with the TypeScript worker #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions demo-angular/app/worker.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Injectable } from "@angular/core";

// add if building with webpack
import * as TsWorker from "nativescript-worker-loader!./workers/typescript.worker";

@Injectable()
export class WorkerService {
constructor() {
}

initTsWorker() {
// add if building with webpack
const worker = new TsWorker();
let worker: any;

// remove if building with webpack
// const worker = new Worker("./workers/typescript.worker");
if ((<any>global).TNS_WEBPACK) {
var TsWorker = require("nativescript-worker-loader!./workers/typescript.worker.js");
worker = new TsWorker();
} else {
worker = new Worker("./workers/typescript.worker.js");
}

return worker;
}
Expand Down
24 changes: 10 additions & 14 deletions demo-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "org.nativescript.webworkerdemo",
"tns-ios": {
"version": "next"
},
"tns-android": {
"version": "next"
"version": "4.2.0"
}
},
"dependencies": {
Expand All @@ -22,23 +19,22 @@
"@angular/platform-browser": "~6.1.0",
"@angular/platform-browser-dynamic": "~6.1.0",
"@angular/router": "~6.1.0",
"nativescript-angular": "rc",
"nativescript-angular": "~6.1.0",
"nativescript-theme-core": "~1.0.2",
"reflect-metadata": "~0.1.8",
"rxjs": "~6.1.0",
"tns-core-modules": "~4.0.0",
"zone.js": "^0.8.4"
"rxjs": "^6.0.0",
"tns-core-modules": "~4.2.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "~6.1.0",
"@ngtools/webpack": "~6.1.0",
"@angular/compiler-cli": "~6.1.7",
"@ngtools/webpack": "~6.2.0",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-typescript": "^0.7.1",
"nativescript-dev-webpack": "next",
"nativescript-dev-typescript": "^0.7.3",
"nativescript-dev-webpack": "^0.16.0",
"ts-loader": "^4.3.0",
"typescript": "~2.7.2",
"verify-ns-build": "github:nativescript/verify-ns-build"
Expand All @@ -48,4 +44,4 @@
"ns-verify-bundle": "ns-verify-bundle",
"update-ns-webpack": "update-ns-webpack"
}
}
}
7 changes: 7 additions & 0 deletions demo-angular/tsconfig.tns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node"
}
}
33 changes: 16 additions & 17 deletions demo-angular/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { join, relative, resolve, sep } = require("path");
const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const { nsReplaceBootstrap } = require("nativescript-dev-webpack/transformers/ns-replace-bootstrap");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
Expand Down Expand Up @@ -46,11 +47,18 @@ module.exports = env => {
const appFullPath = resolve(projectRoot, appPath);
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);

const entryModule = aot ?
nsWebpack.getAotEntryModule(appFullPath) :
`${nsWebpack.getEntryModule(appFullPath)}.ts`;
const entryModule = `${nsWebpack.getEntryModule(appFullPath)}.ts`;
const entryPath = `.${sep}${entryModule}`;

const ngCompilerPlugin = new AngularCompilerPlugin({
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
platformTransformers: aot ? [nsReplaceBootstrap(() => ngCompilerPlugin)] : null,
mainPath: resolve(appPath, entryModule),
tsConfigPath: join(__dirname, "tsconfig.tns.json"),
skipCodeGeneration: !aot,
sourceMap: !!sourceMap,
});

const config = {
mode: uglify ? "production" : "development",
context: appFullPath,
Expand Down Expand Up @@ -107,7 +115,7 @@ module.exports = env => {
test: (module, chunks) => {
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
return /[\\/]node_modules[\\/]/.test(moduleName) ||
appComponents.some(comp => comp === moduleName);
appComponents.some(comp => comp === moduleName);
},
enforce: true,
},
Expand Down Expand Up @@ -177,15 +185,12 @@ module.exports = env => {

// Compile TypeScript files with ahead-of-time compiler.
{
test: /.ts$/, exclude: /.worker.ts$/, use: [
test: /.ts$/, use: [
"nativescript-dev-webpack/moduleid-compat-loader",
"@ngtools/webpack",
]
},

// Compile Worker files with ts-loader
{ test: /\.worker.ts$/, loader: "ts-loader" },

// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
{
Expand All @@ -201,7 +206,7 @@ module.exports = env => {
"process": undefined,
}),
// Remove all files from the out dir.
new CleanWebpackPlugin([ `${dist}/**/*` ]),
new CleanWebpackPlugin([`${dist}/**/*`]),
// Copy native app resources to out dir.
new CopyWebpackPlugin([
{
Expand All @@ -224,19 +229,13 @@ module.exports = env => {
// For instructions on how to set up workers with webpack
// check out https://github.com/nativescript/worker-loader
new NativeScriptWorkerPlugin(),

new AngularCompilerPlugin({
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
entryModule: resolve(appPath, "app.module#AppModule"),
tsConfigPath: join(__dirname, "tsconfig.esm.json"),
skipCodeGeneration: !aot,
sourceMap: !!sourceMap,
}),
ngCompilerPlugin,
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
new nsWebpack.WatchStateLoggerPlugin(),
],
};


if (report) {
// Generate report files for bundles content
config.plugins.push(new BundleAnalyzerPlugin({
Expand Down