我想使用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
标志运行Webpack时
webpack --config ../path/to/file/webpack.config.js
配置文件由Webpack找到并使用,但它给出了一个错误,它找不到循环依赖插件。
似乎Webpack正在node_modules
目录中搜索webpack.config.js
目录,而不是在当前工作目录中。
至少我认为是这样的,我可能是错的。
有没有办法让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']