Last active
January 25, 2022 21:40
-
-
Save webstrand/3c3454dec9dc4bf68a3e67c7eb9f0f22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { fileURLToPath } from "url"; | |
export async function load(url, context, defaultLoad) { | |
if(/\.yaml$/.test(url)) { | |
const path = fileURLToPath(new URL(url)); | |
return { | |
format: "module", | |
source: ` | |
import fs from "fs/promises"; | |
import YAML from 'yaml'; | |
const yamlSource = await fs.readFile(${JSON.stringify(path)}, "utf8"); | |
export default YAML.parse(yamlSource); | |
` | |
} | |
} | |
// Defer to Node.js for all other URLs. | |
return defaultLoad(url, context, defaultLoad); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "yaml-loader", | |
"exports": { | |
".": "./a-yaml-loader.mjs" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment