当使用-config标志时,WebPack找不到node_modules



我想使用当前工作目录之外的webpack.config.js。此外,此webpack.config.js不在我当前工作目录的父级目录中,它在另一个位置分开。

webpack.config.js中,我需要:

const CircularDependencyPlugin = require('circular-dependency-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
... More requires

在我的cmd中,我将位于我的项目目录中,当我使用--config flag

运行WebPack时
webpack --config ../path/to/file/webpack.config.js

配置文件是由WebPack找到和使用的,但它给出了一个错误,它找不到循环依赖性 - plugin。

看来WebPack正在搜索webpack.config.js所在的node_modules目录,而不是在当前的工作目录中。

至少我认为是这样,我可能错了。

有什么办法可以让WebPack在另一个位置读取配置文件,但仍在当前工作目录中使用node_modules

请在解决模块时查看如何指向其他目录。https://webpack.js.org/configuration/resolve/#resolve-modules。简而言之

const baseDir = process.cwd();

和在您的webpack.config.js中添加了

的条目
modules :[path.resolve(path.relative(baseDir,__dirname),'..path to circular dependency']

最新更新