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

时间:2018-03-26 08:56:01

标签: node.js webpack webpack.config.js

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

1 个答案:

答案 0 :(得分:0)

请在此处查看解析模块时如何指向其他目录。 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']
相关问题