Gaweph / p5-typescript-starter

Base starter project using p5js and typescript
MIT License
344 stars 173 forks source link

How do you import/use external libraries? #19

Closed dblock closed 3 years ago

dblock commented 3 years ago

What's the right way to import and use something like https://github.com/kazuhikoarase/qrcode-generator (or https://github.com/1w2w3y/qrcode-generator-ts) into this?

Gaweph commented 3 years ago

1) Add script tag to your index.html <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcode-generator/1.4.4/qrcode.min.js"></script>

2) Add the typings to your project npm install -D qrcode-generator --save

3) Add an import line in your global.d.ts file import qrcode = require('qrcode-generator');

Note: I have updated the tsconfig.json file to include "moduleResolution": "node" (you can get the latest version of this repository or update this file on your own version)

The method outlined above means you can add the script tag to your html and get everything working without anything fancy like webpack etc... keeping it simple (pure js and html).

Let me know if you get stuck.

dblock commented 3 years ago

This worked (https://github.com/dblock/p5qr), thank you. Maybe it could be a section in the README? I can queue it up for myself.

Gaweph commented 3 years ago

Brilliant. Good idea. Happy to include this in the readme.