【笔记】Webpack打包JSON5文件

前言

Webpack打包JSON5文件

下载依赖

1
npm install -D json5

修改配置文件

webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const json5 = require("json5");

module.exports = {
module: {
rules: [
{
test: /\.json5$/,
type: "json",
parser: {
parse: json5.parse,
}
}
]
}
};

引入JSON5文件

  • 引入JSON5文件,得到JS对象
1
2
3
const data = require("./data.json5");

console.log(data); // {}

完成