如何将第三方javascript库与ionic4和电容器一起使用? [英] How to use third party javascript library with ionic4 and capacitor?

查看:72
本文介绍了如何将第三方javascript库与ionic4和电容器一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Ionic 4 angular应用程序和电容器安装第三方javascript库的正确方法是什么?

What is the correct way to install third party javascript libraries with an Ionic 4 angular app and Capacitor?

我尝试如下安装 crunker库:

npm install crunker --save

然后...

import * as crunker from 'crunker';
...
export class MyPage {

  constructor() {}

  doX() { 
     const crunk = new crunker.Crunker();
     ...
  }
  ...
}

其次:

npm run build
npx cap copy
npx cap copy ios
npx cap open ios

但是,当我在IOS模拟器中点击页面时,在控制台中看到以下错误:

However, when I hit the page in the IOS simulator, I see the following error in the console:

TypeError:未定义不是构造函数(正在评估'new crunker__WEBPACK_IMPORTED_MODULE_4 __"Crunker"')

TypeError: undefined is not a constructor (evaluating 'new crunker__WEBPACK_IMPORTED_MODULE_4__"Crunker"')


更新:

按照此答案,我尝试将crunker添加到angular.json,但是出现相同的错误./p>

I have tried adding crunker to angular.json, as per this answer, but I get the same error.

推荐答案

打开 angular.json ,然后将脚本添加到脚本部分.

Open angular.json and add script into scripts section.

"scripts": [
  "../node_modules/crunker/dist/crunker.js"
]

重要的是重建项目后进行 npx cap复制

Important thing is to do npx cap copy after rebuild project

这篇关于如何将第三方javascript库与ionic4和电容器一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆