简体   繁体   English

从 webpack 构建中排除 var 和 json 文件

[英]Exclude var and json file from webpack build

I'm trying to exclude but retain external reference to a few JSON files from a webpack build.我试图从 webpack 构建中排除但保留对一些 JSON 文件的外部引用。

I've modified the webpack.config.js to include:我修改了 webpack.config.js 以包括:

externals: {
        "../package.json": "package_json",
        "./font.json": "font"  
},

This solved some previous errors, but now it seems that the 'font' var is being considered undefined.这解决了以前的一些错误,但现在似乎 'font' var 被认为是未定义的。

Uncaught ReferenceError: font is not defined

The error is referring to this line in the build, where webpack has exported the 'font' var as a module.export:错误是指构建中的这一行,其中 webpack 已将“字体”变量导出为 module.export:

/!***********************!
!*** external "font" *!
********************/
/**/ function(module, exports) {

module.exports = font;

When comparing the original code to the webpack build, webpack converted this:当将原始代码与 webpack 构建进​​行比较时,webpack 将其转换为:

var font = require('./font.json'),
    Theme = require('./theme'),
    style = require('./utils').style;

to this:对此:

'use strict';

var font = __webpack_require__(/*! ./font.json */ 334),
    Theme = __webpack_require__(/*! ./theme */ 324),
    style = __webpack_require__(/*! ./utils */ 326).style;

Which seems to leave 'font' undefined?哪个似乎没有定义“字体”? How is webpack handling this var value here? webpack 是如何处理这个 var 值的?

Webpack is somewhat new to me. Webpack 对我来说有些陌生。 Any insights into how to resolve this?有关如何解决此问题的任何见解?

我用 json-loader 找到了解决方案:npmjs.com/package/json-loader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM