Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/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
Webpack 为什么网页包加载器返回时带有;module.exports=…”;?_Webpack - Fatal编程技术网

Webpack 为什么网页包加载器返回时带有;module.exports=…”;?

Webpack 为什么网页包加载器返回时带有;module.exports=…”;?,webpack,Webpack,为什么装载机返回 return“module.exports=“+JSON.stringify(输入)”; 而不是返回JSON.stringify(输入) 这有什么意义 这是json加载程序 /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ module.exports = function(source) { this.cac

为什么装载机返回 return“module.exports=“+JSON.stringify(输入)”; 而不是返回JSON.stringify(输入)

这有什么意义

这是json加载程序

/*
    MIT License http://www.opensource.org/licenses/mit-license.php
    Author Tobias Koppers @sokra
*/
module.exports = function(source) {
    this.cacheable && this.cacheable();
    var value = typeof source === "string" ? JSON.parse(source) : source;
    this.value = [value];
    return "module.exports = " + JSON.stringify(value) + ";";
}

无论是JSON、图像还是其他文件类型,Webpack的加载程序都将始终返回导出内容的JS模块,以便将其作为依赖项导入到Webpack生成的其他模块中,如果您使用不同的模块标准(AMD、UMD等),则在生成模块后应用其他转换

如果您希望绕过Webpack的模块解析和插件转换,那么您应该使用。通过这种方式,您将获得原始JSON文件,但是您必须知道公共URL,并通过XHR或
fetch()
,自己加载该文件,然后才能在源代码中使用它