【发布时间】:2018-01-01 05:52:18
【问题描述】:
问题:有没有办法告诉 webpack 告诉像 fs 这样的内置模块在构建期间执行,以便浏览器得到这个函数的结果,而不是函数调用本身?
我的情况:
目前我正在使用 webpack 为浏览器开发一个应用程序。我正在尝试在我的文件中使用节点“fs”模块来要求来自其他目录的index.js 文件。例如:
plugins
├──plugin1
│ ├── index.js (simply exports an object)
│
├──plugin2
│ ├── index.js (simply exports an object)
|
├──plugin3
│ ├── index.js (simply exports an object)
|
|──index.js (want to require all index.js from each plugin directory here)
我收到一个 webpack 错误提示:Can't resolve 'fs' in somepath/node_modules/require-dir
我的文件 index.js 位于 `plugins/index.js',它只是试图要求我的其他文件。
//module from NPM which uses the 'fs' module ('im not explicity using it)
const requireDir = require('require-dir');
const allPlugins = requireDir('./plugins/');
console.log(allPlugins);
无法解析“/some_path/node_modules/require-dir”中的“fs”
【问题讨论】:
-
你能把你要导入的来源
fs贴出来吗?
标签: javascript node.js webpack webpack-2