[Webpack 2] Expose modules to dependencies with Webpack

时间:2023-03-09 02:17:45
[Webpack 2] Expose modules to dependencies with Webpack

When you have a dependency that has dependencies on global variables (like jQuery or lodash) or assumes that this is bound to window, you can use the imports-loaderto provide those dependencies explicitly.

In case there is one dependency that we use need lodash, but didn't includes lodash as dependency.

One way to solve the problem is that we can include lodash as denpedency in our application.

Another way is expose lodash to that library, to do that, you need to Install:

npm i -D imports-loader

Add to webpack config:

        {
test: require.resolve('./src/js/non_node_modules/sweet-lodash-mixins'),
loader: 'imports?_=lodash'
}