Nativescript Angular + Webpack + Onesignal插件

时间:2017-06-08 12:14:23

标签: angular webpack nativescript onesignal

我目前正在开发一个使用OneSignal NS插件进行推送通知的项目。

它工作正常,它用于在启用Webpack之前正确构建/运行,直到我开始使用OneSignal插件。

我并不完全了解如何配置我的项目以获得Webpack构建。

这是我所指的插件:https://github.com/roblav96/nativescript-onesignal

它要求在源代码上添加这一行以使用它(这是我目前正在做的),所以我做了,例如,在一个名为main.module.ts的文件中:

let TnsOneSignal = require("nativescript-onesignal").TnsOneSignal;

我发现我应该注册我正在使用Webpack的模块,我尝试过一些东西,但它没有用。

这样的事情:

global.registerModule("nativescript-onesignal", ()=> require('../nodemodules/nativescript-onesignal'));

我得到的错误是这样的:

ERROR in ./modules/main/main.module.ts
Module not found: Error: Can't resolve 'nativescript-onesignal' in 
'EDITED-APP-PATH/my-app/app/modules/main'
@ ./modules/main/main.module.ts 8:19-52
@ ./app.module.ngfactory.ts
@ ./main.aot.ts

我在这个论坛上找到了一些主题:https://discourse.nativescript.org,但我无法从中获得任何有用的解决方案。

任何帮助或提示都将不胜感激。

这是我目前的package.json:

{
  "description": "App",
  "license": "LicenseRef-LICENSE",
  "readme": "README",
  "nativescript": {
    "id": "com.app.name"
  },
  "dependencies": {
    "@angular/animations": "~4.1.0",
    "@angular/common": "~4.1.0",
    "@angular/compiler": "~4.1.0",
    "@angular/core": "~4.1.0",
    "@angular/forms": "~4.1.0",
    "@angular/http": "~4.1.0",
    "@angular/platform-browser": "~4.1.0",
    "@angular/router": "~4.1.0",
    "nativescript-angular": "~3.0.0",
    "nativescript-iqkeyboardmanager": "^1.0.1",
    "nativescript-localize": "^2.0.1",
    "nativescript-onesignal": "^1.0.6",
    "nativescript-telerik-ui": "^2.0.1",
    "nativescript-theme-core": "~1.0.2",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~5.3.0",
    "tns-core-modules": "^3.0.1",
    "zone.js": "~0.8.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~4.1.0",
    "@ngtools/webpack": "1.3.1",
    "babel-traverse": "6.24.1",
    "babel-types": "6.24.1",
    "babylon": "6.17.1",
    "copy-webpack-plugin": "~4.0.1",
    "extract-text-webpack-plugin": "~2.1.0",
    "lazy": "1.0.11",
    "nativescript-css-loader": "~0.26.0",
    "nativescript-custom-entitlements": "^0.2.0",
    "nativescript-dev-sass": "^1.1.1",
    "nativescript-dev-typescript": "~0.4.0",
    "nativescript-dev-webpack": "^0.6.0",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.0.2",
    "tns-platform-declarations": "^3.0.0-rc.2",
    "typescript": "~2.2.1",
    "webpack": "~2.5.1",
    "webpack-sources": "~0.2.3"
  },
  "scripts": {
    "ns-bundle": "ns-bundle",
    "start-android-bundle": "npm run ns-bundle --android --start-app",
    "start-ios-bundle": "npm run ns-bundle --ios --start-app",
    "build-android-bundle": "npm run ns-bundle --android --build-app",
    "build-ios-bundle": "npm run ns-bundle --ios --build-app",
    "publish-ios-bundle": "npm run ns-bundle --ios --publish-app"
  }
}

1 个答案:

答案 0 :(得分:1)

我会将Nick Illiev的评论标记为我的问题的正确答案。

Nativescript Angular + Webpack + Onesignal plugin

谢谢!