我想使用当前工作目录之外的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 --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']