serlingpa serlingpa - 1 year ago 269
Javascript Question

PDF Viewer for Ionic 2: cannot import or require

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.

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

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.

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

Answer Source

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.


The root of the www folder does not change and you can reference it as someting like ... '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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download