esbuild-yaml
Version:
An esbuild plugin, that allows imports of YAML files
92 lines (66 loc) • 1.81 kB
Markdown
using different bundlers than esbuild, you could try [`unplugin-yaml`](https://github.com/luxass/unplugin-yaml)
> which supports all different kinds of bundlers, powered by unplugin.
```sh
npm install --save-dev esbuild-yaml esbuild
```
Add this to your build file
```js
import { build } from "esbuild";
import { YAMLPlugin } from "esbuild-yaml";
const yourConfig = {};
build({
...yourConfig,
plugins: [
YAMLPlugin()
]
});
```
If you are using TypeScript, you need to add the following to your `tsconfig.json` file:
```json
{
"compilerOptions": {
"types": [
"esbuild-yaml/types"
]
}
}
```
```js
// build.js
import { build } from "esbuild";
import { YAMLPlugin } from "esbuild-yaml";
const yourConfig = {};
build({
...yourConfig,
plugins: [
YAMLPlugin()
]
});
```
```yaml
name: esbuild-yaml
version: 1.0.0
```
```ts
// index.ts
import config from "./config.yaml"; // this will be converted to a JSON object
import configRaw from "./config.yaml?raw"; // this will be the raw YAML string
console.log(config); // { name: "esbuild-yaml", version: "1.0.0" }
console.log(configRaw); // name: esbuild-yaml\nversion: 1.0.0
```
Published under [MIT License](./LICENSE).
<!-- Badges -->
[ ]: https://img.shields.io/npm/v/esbuild-yaml?style=flat&colorA=18181B&colorB=4169E1
[ ]: https://npmjs.com/package/esbuild-yaml
[ ]: https://img.shields.io/npm/dm/esbuild-yaml?style=flat&colorA=18181B&colorB=4169E1
[ ]: https://npmjs.com/package/esbuild-yaml
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
> [!NOTE]
> If you are