[Webpack 2] Expose modules to dependencies with Webpack
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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‘ }
以上是关于[Webpack 2] Expose modules to dependencies with Webpack的主要内容,如果未能解决你的问题,请参考以下文章
我啥时候在 Webpack 2 module.rules 中使用“use”和“loader”?
[Webpack 2] Import a non-ES6 module with Webpack
[Webpack 2] Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin