Skip to content Skip to sidebar Skip to footer

Importing "regular" Javascript Packages Installed With Npm In Webpack

I've npm installed smooth-scroll, a package which does not support the import syntax. I am sure it will work If I manually copy the source code to the libs library and use a script

Solution 1:

The simplest answer would be to go into the source code of smooth-scroll.js and to add to the bottom:

exportdefault smoothScrollFunction;

Where smoothScrollFunction is the function / object / whatever that you're wanting to import. Then the import statement would work in other code using:

import scroller from"./lib/smooth-scroller";

That's how importing and exporting works with ES2015. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

Post a Comment for "Importing "regular" Javascript Packages Installed With Npm In Webpack"