如何在 webpack 中使用别名来覆盖 node_modules 中已经存在的依赖项?

Dim*_*iwa 3 javascript npm node-modules reactjs webpack

在 Webpack 4 中,

我想把我的rsg-components而不是一个放在node_modules.

所以react-styleguidist将导入我的版本。

显然resolve.alias不优先node_modules,有没有办法在不分叉的情况下这样做react-stylguidist

luk*_*eke 5

您可以使用解析模块
只需添加您的模块所在的目录之前node_modules

从文档:

如果要添加一个优先于 node_modules/ 的目录进行搜索:

modules: [path.resolve(__dirname, "src"), "node_modules"]
Run Code Online (Sandbox Code Playgroud)