How to use packaged modules in a non-node JS environment?

1.4k views Asked by At

With the exception of node API usage (fs, http, net...), vanilla js remains executable on any engine. Simple functionality can be relatively easily "plucked" from a packaged module (provided the licensing terms are met), but this gets messy for larger modules.

Is there a straightforward/less-frowned-upon way to use a module in an arbitrary environment? Ideally such a npm2notnpm bridge would be able to interface with the complete module as forked, there is also no expectation to have it work in 100% cases :)

Why?.. the CMS engine we have to work with can execute arbitrary javascript using Spidermonkey engine (on the server); unfortunately that's the only way to build anything functional on the platform. I'd like to be able to leverage available packages as much as possible (cheerio on the wishlist) rather than re-inventing the wheel or copy-pasting code without context.

1

There are 1 answers

1
Patrick Gunderson On BEST ANSWER

You can use Require.js to load many Common.js packaged modules. Or you could define exports = window and pass that to the module to get access to the module.

http://requirejs.org/docs/commonjs.html