Package Exports
- yaml-to-js.macro
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (yaml-to-js.macro) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
yaml-to-js.macro
Babel macro to convert yaml template strings to javascript objects at build time.
From:
import yml from "yaml-to-js.macro"
const foo = yml`
config:
a: 10
b:
- 1
- 2
`;
To:
const foo = {
config: {
a: 10,
b: [1, 2]
}
}
It handles interpolated expressions reasonably well:
From:
import yml from "yaml-to-js.macro"
const a = 10
const b = 20
const foo = yml`
config:
a: ${10}
b:
- ${a}
- ${a + b}
`;
To:
const a = 10
const b = 20
const foo = {
config: {
a: 10,
b: [a, a+b]
}
}
Configuration
This macro relies on babel & babel-plugin-macros being configured properly.
If you are not familiar with babel, checkout the usage guide.
If you are not familiar with babel-plugin-macros, checkout the introduction and the installation section.
Recommended configuration:
npm install --save-dev @babel/core babel-plugin-macros yaml-to-js.macro
In .babelrc
:
{
"plugins": ["babel-plugin-macros"]
}
License
MIT