【问题标题】:JSON files are included in the bundleJSON 文件包含在包中
【发布时间】:2019-02-02 07:43:15
【问题描述】:

webpack 在 bundle 中包含 .json 文件

我试试这个

const data = require('./header.json');

如果我使用 json-loader

{
  test: /\.json?$/,
  loader: 'json-loader',
  options: {
    name: '[hash].[ext]',
    publicPath: assetsPath + 'constants/',
    outputPath: 'assets/json',
  },
},

然后我收到以下错误 模块解析失败:在 'module.exports = {"l...' 您可能需要适当的加载程序来处理此文件类型。

我需要在构建后我可以更改 json 文件

【问题讨论】:

  • 您确定您的json 有效吗?
  • 是的,json有效

标签: webpack


【解决方案1】:

我不知道它是否有帮助,但你不需要 json-loader 来处理 json 文件。您可以使用file-loader 导入 json 文件。它不需要任何配置。只要确保安装了file-loader

【讨论】:

  • 如果我使用文件加载器,我会收到错误模块解析失败:在位置 0 的 JSON 中出现意外的令牌 m,同时在 'module.exports = __w...' 附近进行解析您可能需要一个合适的加载器处理这种文件类型。
  • 那个奇怪的原因是我在我的应用程序中使用file-loader 加载了 json 文件。也许json文件不正确!你可以在这里添加你的文件吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-21
  • 1970-01-01
  • 1970-01-01
  • 2021-11-09
  • 1970-01-01
  • 1970-01-01
  • 2012-02-13
相关资源
最近更新 更多