esm-loader-yaml
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

MIT

Author

Larry Maccherone @lmaccherone

Package Sidebar

Install

npm i esm-loader-yaml

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

5.8 kB

Total Files

4

Last publish

Collaborators

  • brev