luxass / esbuild-yaml

πŸ“¦ A esbuild plugin that allow import of yaml files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

esbuild-yaml

npm version npm downloads

πŸ“¦ Installation

npm install --save-dev esbuild-yaml esbuild

πŸ“š Usage

Add this to your build file

import { build } from "esbuild";
import { YAMLPlugin } from "esbuild-yaml";

const yourConfig = {};

build({
  ...yourConfig,
  plugins: [
    YAMLPlugin()
  ]
});

TypeScript

If you are using TypeScript, you need to add the following to your tsconfig.json file:

{
  "compilerOptions": {
    "types": [
      "esbuild-yaml/types"
    ]
  }
}

πŸ“– Examples

// build.js
import { build } from "esbuild";
import { YAMLPlugin } from "esbuild-yaml";

const yourConfig = {};

build({
  ...yourConfig,
  plugins: [
    YAMLPlugin()
  ]
});
# config.yaml
name: esbuild-yaml

version: 1.0.0
// 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

πŸ“„ License

Published under MIT License.

About

πŸ“¦ A esbuild plugin that allow import of yaml files

License:MIT License


Languages

Language:TypeScript 98.1%Language:JavaScript 1.9%