如果文件路径使用字符串变量concat,则webpack require失败
我一直遇到奇怪的网页需求问题。若我在require字符串中使用变量,它将无法加载任何内容,但不会加载错误消息。但使用完整路径字符串将成功加载。你知道发生了什么事吗如果文件路径使用字符串变量concat,则webpack require失败,webpack,Webpack,我一直遇到奇怪的网页需求问题。若我在require字符串中使用变量,它将无法加载任何内容,但不会加载错误消息。但使用完整路径字符串将成功加载。你知道发生了什么事吗 var _commonFolder = '../Presentation/Base/Default/js/source/_common/' require(_commonFolder + 'docReady.js'); // the above require will fail to load anything, but no er
var _commonFolder = '../Presentation/Base/Default/js/source/_common/'
require(_commonFolder + 'docReady.js');
// the above require will fail to load anything, but no error message
require('../Presentation/Base/Default/js/source/_common/docReady.js');
// the above require successfully load the content
我想,您尝试做的是在文件的动态要求下进行的 阅读网页文档解释 在这里,
docReady.js
不会被捆绑,因为它包含表达式\u commonFolder+'docReady.js
,并且在编译和捆绑时无法通过webpack解决
在像您这样的情况下,在获取require中的表达式时,webpack可能会在捆绑输出文件中创建一个表达式
鉴于
require('../Presentation/Base/Default/js/source/_common/docReady.js');
当您提供完整的相对路径时,将通过webpack绑定docReady.js
require('../Presentation/Base/Default/js/source/_common/docReady.js');