Ionic 2的PDF查看器:无法导入或要求

时间:2021-02-04 23:00:21

I am trying to build a PDF viewing component for an Ionic 2 app. I have lots of experience of Angular 2, but not of Ionic.

我正在尝试为Ionic 2应用程序构建PDF查看组件。我有很多Angular 2的经验,但不是Ionic的经验。

The component will be built using pdf.js and have created the pdf.js asset to be included in my project as described on the github page. However, trying to require this fails — require is not defined —, so I copied the script to the asset folder and tried importing it. It seems the file is not being copied to the build so that fails too.

该组件将使用pdf.js构建,并创建了pdf.js资产,以便包含在我的项目中,如github页面所述。但是,尝试要求此操作失败 - require未定义 - 因此我将脚本复制到资产文件夹并尝试导入它。似乎文件没有被复制到构建中,所以也失败了。

Anyone have any pointers for requiring or importing a non-weboack non-SystemJS script into an Ionic 2 app?

任何人都有任何指针要求或将非weboack非SystemJS脚本导入Ionic 2应用程序?

2 个解决方案

#1


1  

Create a js folder (or something like this) in the www folder; include the files needed and reference them from there. This folder is not emptied on build.

在www文件夹中创建一个js文件夹(或类似的东西);包括所需的文件并从那里引用它们。此文件夹在构建时未清空。

EDIT

The root of the www folder does not change and you can reference it as someting like ... 'js/need-this.js'.

www文件夹的根目录不会改变,你可以像...'js / need-this.js'那样引用它。

There should have some references in your index.html file to the build folder and maybe the assets folder (icon); this concept of using a js folder works the same. Only build and assets will change.

你的index.html文件中应该有一些引用到build文件夹,也许是assets文件夹(icon);这个使用js文件夹的概念也是一样的。只有构建和资产才会发生变化。

#2


1  

I feel that I should point out that you shouldn't copy anything into www since this is autogenerated and any changes will be overwritten. You should copy into assets instead.

我觉得我应该指出你不应该将任何内容复制到www中,因为这是自动生成的,任何更改都将被覆盖。您应该复制到资产中。

#1


1  

Create a js folder (or something like this) in the www folder; include the files needed and reference them from there. This folder is not emptied on build.

在www文件夹中创建一个js文件夹(或类似的东西);包括所需的文件并从那里引用它们。此文件夹在构建时未清空。

EDIT

The root of the www folder does not change and you can reference it as someting like ... 'js/need-this.js'.

www文件夹的根目录不会改变,你可以像...'js / need-this.js'那样引用它。

There should have some references in your index.html file to the build folder and maybe the assets folder (icon); this concept of using a js folder works the same. Only build and assets will change.

你的index.html文件中应该有一些引用到build文件夹,也许是assets文件夹(icon);这个使用js文件夹的概念也是一样的。只有构建和资产才会发生变化。

#2


1  

I feel that I should point out that you shouldn't copy anything into www since this is autogenerated and any changes will be overwritten. You should copy into assets instead.

我觉得我应该指出你不应该将任何内容复制到www中,因为这是自动生成的,任何更改都将被覆盖。您应该复制到资产中。