A Babel macro for loading YAML files at build time, transforming YAML into JavaScript objects via babel-plugin-macros. Current stable version is 0.2.0, released infrequently. It uses the `yaml` package under the hood and supports all its parser options. Key differentiators: integrates seamlessly with Babel macros, evaluated at build time (not runtime), supports any YAML 1.2 types. Unlike runtime YAML loaders, this macro inlines data at compile time, reducing bundle size and runtime overhead. Requires Node.js >=10 and babel-plugin-macros.
npm install yaml.macroVerified import paths — ran on the pinned version, not inferred.
Shows setup with babel-plugin-macros, a YAML file, and importing/using yaml.macro to inline YAML content at build time.
Use a constant string: yaml('./myfile.yaml') not yaml(filePathVariable)Assign the result to a variable and reuse it: const data = yaml('./file.yaml'); then use data multiple times.Upgrade Node.js to version 10 or higher.
Refer to yaml package changelog for breaking changes between versions.
Use import yaml from 'yaml.macro'
npm install --save-dev babel-plugin-macros
yaml('./your-file.yaml') — path must be a string literal