Js browserify 要求字符串数组不起作用
Js browserify require from array of strings does not working
我正在尝试遍历字符串数组并使用 require 要求它们,但由于某种原因,这不起作用。
这是有效的:
console.log(require('./siteParts/testis'));
这不是:
var siteParts = ['testis'];
siteParts.forEach(function(part) {
console.log(require('./siteParts/' + part));
Error: Cannot find module './siteParts/testis'
});
恐怕这是 [status-bydesign],使用 SE 术语。 Browserify 使用简单的文本解析,只搜索正常的 require('some module name')
。不会包含任何动态解析的内容。
我正在尝试遍历字符串数组并使用 require 要求它们,但由于某种原因,这不起作用。
这是有效的:
console.log(require('./siteParts/testis'));
这不是:
var siteParts = ['testis'];
siteParts.forEach(function(part) {
console.log(require('./siteParts/' + part));
Error: Cannot find module './siteParts/testis'
});
恐怕这是 [status-bydesign],使用 SE 术语。 Browserify 使用简单的文本解析,只搜索正常的 require('some module name')
。不会包含任何动态解析的内容。