LearningToCode LearningToCode - 10 months ago 45
Node.js Question

How to require custom dependency inside project using webpack

I am trying to import my custom library inside my main class.
my custom library is inside bower_components directory.
The Path is:

->customLib -> dist -> mainClass.js

bower.json of the custom library has the main classes mentioned.

In the minified version of my project I do see the customLib library included.It looks something like this:

/***/ function(module, exports) {
var A= function () {
return A;

I am trying to access variable A inside the customLib from main js file of my project.

require("customLib ") does not work.

I am not sure how to import the library in such case.I am very new to webpack.It would be really helpful if someone could point me into right direction.

Thank you for your time and help.

Answer Source

All you need to do is to export A from your library (edit your mainClass.js file):

module.exports = { A: A };

Then you can access it through require: