Sunday 30 August 2020

Not sure how to export a library meant to be used in front-end code...

I've written a library called When. It's a keyboard shortcut library, meant for front end use, not in back end code.In my code, I make a function called When() globally available on the window object so that you can just call that anywhere in your code.Currently, my instructions for installation/use with a bundler like webpack (after installing via NPM) are to import 'when-key-events', then either use window.When() or do const When = window.When in order to use it, otherwise you get errors like "When is not defined" even though it's a global.Obviously other libraries get around this somehow but I'm not sure how exactly...since all the code is targeted for use in the browser, I can't do a node style export or a module.exports = When can I? I tried doing similar things but it doesn't seem to be working.What am I missing? How would I achieve something like import { When } from 'when-key-events' while keeping the code browser compatible for use over the CDN?For reference, the source is written in Typescript, and bundled using Webpack into a single dist file.

Submitted August 31, 2020 at 04:08AM by PM_ME_A_WEBSITE_IDEA

No comments:

Post a Comment