0.0.1 • Published 3 years ago
rollup-plugin-yamlx v0.0.1
rollup-plugin-yamlx
🍣 An enhanced Rollup/Vite plugin which converts YAML files to ES6 modules.
Install
$ npm install -D rollup-plugin-yamlx
# or
# yarn add -D rollup-plugin-yamlx
Usage
Create a rollup.config.js
configuration file and import the plugin:
import PluginYamlX from 'rollup-plugin-yamlx'
export default {
plugins: [PluginYamlX()]
}
Then call rollup
either via the CLI or the API.
With an accompanying file src/index.js
, the local heroes.yaml
file would now be importable as seen below:
// src/index.js
import { batman } from './heroes.yaml?named';
console.log(`na na na na ${batman}`);
Options
Import Options
Users can use below query params in import path to specify how the plugin converts yaml to esm.
multi
- get an array of documents of the yaml file.single
- get one of the documents of the yaml file.index
- useindex
to specify which one document should be returned when 'single' is enabled.named
- generate named-exports for the top-level fields of the returned document.no-named
- do not generate named-exports. This option is always enabled when 'multi' enabled.default
- generate default-export for the returned document.no-default
- do not generate default-export for the returned document.
By default single
and default
is enabled, and index
is 0,
which means you can get default-export of the first document in some.yaml
easily:
import doc from 'some.yaml'
See test cases for more examples.
Plugin Options
declare type YamlXOptions = {
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should operate on.
* By default all files are targeted.
*/
include?: FilterPattern;
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should _ignore_.
* By default no files are ignored.
*/
exclude?: FilterPattern;
/**
* A function which can optionally mutate parsed YAML.
* The function should return the mutated result, or `undefined` which will make no changes to
* the parsed YAML.
*/
transform?: (data: ValidYamlType, filePath: string) => ValidYamlType | undefined;
/**
* Schema used to parse yaml files.
* See https://github.com/nodeca/js-yaml/blob/49baadd52af887d2991e2c39a6639baa56d6c71b/README.md#load-string---options-
*/
schema?: Schema;
};
License
MIT License © 2021 unbyte
0.0.1
3 years ago