【笔记】Webpack打包Yaml文件

前言

Webpack打包Yaml文件

下载依赖

1
npm install -D yaml

修改配置文件

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

module.exports = {
module: {
rules: [
{
test: /\.(yaml|yml)$/,
type: "json",
parser: {
parse: yaml.parse,
}
}
]
}
}

引入Yaml文件

  • 引入Yaml文件,得到JS对象
1
2
3
import data from "./data.yaml"

console.log(data); // {}

完成