Javascript 需要网页包中的模块数组
我目前正在尝试用Webpack加载模块的可变数组。 我找到了这个链接:但它似乎对我不起作用 在我的项目中,我的node_modules文件夹中有一个模块。模块的入口点称为index.js 以下是基本结构:Javascript 需要网页包中的模块数组,javascript,webpack,Javascript,Webpack,我目前正在尝试用Webpack加载模块的可变数组。 我找到了这个链接:但它似乎对我不起作用 在我的项目中,我的node_modules文件夹中有一个模块。模块的入口点称为index.js 以下是基本结构: | app +---app.js | js +---gen.js | node_modules +---sample_module_1 | +---index.js +-sample-module_2 +---index.js | webpack.config.js
| app
+---app.js
| js
+---gen.js
| node_modules
+---sample_module_1
| +---index.js
+-sample-module_2
+---index.js
| webpack.config.js
在未来,我想添加新的模块。因此,我尝试了以下方法:
//app.js
var modules = [
"sample_module_1",
"sample_module_2"
]
for(var i = 0; i < modules.length; i++) {
require(modules[i] + "/index.js");
}
不过,Webpack无法找到该模块
我也尝试过这些建议,但仍然没有结果
有什么建议吗?您的webpack.config.js可能有助于调试。同样,包的布局以及节点_模块也会有所帮助。您的webpack.config.js可能有助于调试。同样,包的布局以及节点_模块也会有所帮助。
//webpack.config.js
var path = require('path');
module.exports = {
entry: './app/app.js',
output: {
filename: 'gen.js',
path: path.resolve(__dirname, 'js')
},
resolveLoader: {
modules: ["node_modules"],
extensions: ['*', '.js']
}
};