1.0.3 • Published 2 years ago
@luxass/esbuild-yaml v1.0.3
esbuild-yaml
This plugin allows you to import YAML files with ESBUILD
📦 Installation
npm install --save-dev @luxass/esbuild-yaml
📚 Usage
Add this to your build file
import { build } from "esbuild";
import { YAMLPlugin } from "@luxass/esbuild-yaml";
const yourConfig = {};
build({
...yourConfig,
plugins: [
YAMLPlugin()
]
});
TypeScript
If you are using TypeScript, you will need to add a type declaration file to your project.
// esbuild-yaml.d.ts
declare module "*.yaml" {
const value: Record<string, unknown>;
export default value;
}
declare module "*.yml" {
const value: Record<string, unknown>;
export default value;
}
declare module "*.yaml?raw" {
const value: string;
export default value;
}
declare module "*.yml?raw" {
const value: string;
export default value;
}
📖 Examples
// build.js
import { build } from "esbuild";
import { YAMLPlugin } from "@luxass/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.