Using commonjs modules in Angular4 services?

1.1k Views Asked by At

I first tested using the commonjs module that I installed like this:

npm install the-module;

I then created main.js which looked something like this:

var module = require('the-module');
module.doStuff();

Then compiled main.js with webpack into bundle.js, loaded it in the browser, and it did stuff.

Now I want to use the-module inside an angular 4 service. How should I import it?

I also found this article on how to create an angular 2 component library. Curious whether this set of steps is required for all commonjs modules that will be imported by Angular or whether there is a more direct approach?

Related Concepts

Ended up writing this article:

using-vanilla-npm-javascript-modules-with-typescript

0

There are 0 best solutions below