#load/parse yaml file at compile time?

14 messages · Page 1 of 1 (latest)

livid zenith
#

Hi! I have a yaml file that is used to describe a series of items. For example, it might look like this: ```yaml

  • name: apple
    description: red and shiny
    id: 1

  • name: grapes
    description: comes in a bushel
    id: 2

...

When I go to build my webapp, I'd like to compile everything into 1 javascript file. Is there a way to include the yaml file in the build?

In golang I'd be able to do something like this: ```go
//go:embed items.yml
var ITEMS string

items.yml would be loaded into the ITEMS variable at compile time, and I'd be able to use it accordingly. I know I can just do ```js
const ITEMS = `

yaml here

`

However, then I can't take full advantage of editor support for yaml.
stable garnet
livid zenith
#

thanks, I think that might be what I'm looking for

stable garnet
#

That converts it to JSON though, if you just want the text for the YAML file there's probably an easier approach

livid zenith
#

I'm fine with it being converted in the actual build. For maintaining it on the dev side though it'd be handy to keep it as yaml

stable garnet
#

Probably just

import Items from "./items.yml?raw";
livid zenith
#

oh that could work too. I'll give that a read through

stable garnet
#

Though if you can avoid YAML altogether I would

#

JSON being a 'native language' for JS makes it a lot more convenient to work with in TS.

livid zenith
#

hm, that is a fair point

#

It's not too late to chaneg to JSON either

#

I'll look at everything you sent + that and see which solution makes the most sense

stable garnet