Js browserify 需要从字符串数组不起作用

Js browserify require from array of strings does not working

本文关键字:字符串 数组 不起作用 browserify Js      更新时间:2023-09-26

我正在尝试遍历字符串数组并要求它们,但由于某种原因这不起作用。

这是有效的:

console.log(require('./siteParts/testis'));

这不是:

var siteParts = ['testis'];
siteParts.forEach(function(part) {
  console.log(require('./siteParts/' + part));
  Error: Cannot find module './siteParts/testis'
});

恐怕这是[状态设计],用SE术语来说。浏览器化使用文本的朴素解析,只搜索正常的require('some module name')。任何动态解析的内容都不会包括在内。