First things first, add your scripts to the index.html page. Don’t worry about the location, we’ll fix it later. In my scenario, I needed to include these 3 libraries that rollup doesn’t play nice with, along with font-awesome.
<link href="css/font-awesome.min.css" rel="stylesheet">
Next thing we do is add these three files to your project. You have some choices here. Choose your preference.
- Add them via
libs, and put it in my
Now we tell ionic to copy these files when doing a build.
Create a folder named
config in your project root.
Copy the following file
node_modules/@ionic/app-scripts/config/copy.config.js to this folder.
src: 'src/libs/', //copy all files from here
dest: 'www/libs/' //and put them here
Last step. Tell ionic to use your copy.config.js file rather than the default one
package.json and add an config entry. Doesn’t matter where you add it.
All done. Run
BUT WAIT. THERE’S MORE!!
Need to tell Typescript to ignore things. In my case I would put this at the top of my
.ts file that I use these libraries in
declare var forge: any;
declare var TextEncoder: any;
You could get reeeal fancy and put all this into a single
declarations.d.ts file, as mentioned here
Once all this nonsense with rollingup, tree-shaking, angular compiling, typescript definition crap is sorted out, and the authors of these fine libraries migrate from CommonJs to ES5 modules, then I’ll remove my work-around.
Hope this helps.
Links that helped me.