Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果文件路径使用字符串变量concat,则webpack require失败_Webpack - Fatal编程技术网

如果文件路径使用字符串变量concat,则webpack 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

我一直遇到奇怪的网页需求问题。若我在require字符串中使用变量,它将无法加载任何内容,但不会加载错误消息。但使用完整路径字符串将成功加载。你知道发生了什么事吗

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');