esm-loader-yaml
v1.0.2
Published
Chainable ESModule Loader for importing YAML files as modules
Downloads
4
Maintainers
Readme
esm-loader-yaml
Node.js ESModule Loader for importing YAML files as modules.
Warning! This uses experimental Node.js features and flags, whose API will likely change. This code may be helpful for development and testing, but should not be used in production.
Usage
npm install --save-dev esm-loader-yaml
You may have code which imports .yaml
files:
## data.yaml
- name: Vito
// index.js
import data from './data.yaml'
console.log(data) // { "name": "Vito" }
Standalone
# node >= 20.7
cat << EOF > ./register.js
import { register } from 'node:module'
register('esm-loader-yaml', import.meta.url)
EOF
NODE_OPTIONS="--import ./register.js" node index.js
# node < 20.7
NODE_OPTIONS="--loader esm-loader-yaml" node index.js
Chainable
This loader can be configured, and chained with other loaders, using node-esm-loader.
npm install --save-dev node-esm-loader
// .loaderrc.js
export default {
loaders: ['esm-loader-yaml'],
}
# node >= 20.7
NODE_OPTIONS="--import node-esm-loader/register" node index.js
# node < 20.7
NODE_OPTIONS="--loader node-esm-loader" node index.js
Options
Debug
// .loaderrc.js
export default {
loaders: [
{
loader: 'esm-loader-yaml',
options: {
debug: true,
},
},
],
}
License
Author
Larry Maccherone @lmaccherone