UNPKG

3.05 kBMarkdownView Raw
1[npm]: https://img.shields.io/npm/v/@rollup/plugin-yaml
2[npm-url]: https://www.npmjs.com/package/@rollup/plugin-yaml
3[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-yaml
4[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-yaml
5
6[![npm][npm]][npm-url]
7[![size][size]][size-url]
8[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
9
10# @rollup/plugin-yaml
11
12🍣 A Rollup plugin which Converts YAML files to ES6 modules.
13
14## Requirements
15
16This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
17
18## Install
19
20Using npm:
21
22```console
23npm install @rollup/plugin-yaml --save-dev
24```
25
26## Usage
27
28Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
29
30```js
31import yaml from '@rollup/plugin-yaml';
32
33export default {
34 input: 'src/index.js',
35 output: {
36 dir: 'output',
37 format: 'cjs'
38 },
39 plugins: [yaml()]
40};
41```
42
43Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
44
45With an accompanying file `src/index.js`, the local `heroes.yaml` file would now be importable as seen below:
46
47```js
48// src/index.js
49import { batman } from './heroes.yaml';
50
51console.log(`na na na na ${batman}`);
52```
53
54## Options
55
56### `documentMode`
57
58Type: `String`<br>
59Default: `single`
60
61If `single`, specifies that the target YAML documents contain only one document in the target file(s). If more than one [document stream](https://yaml.org/spec/1.2/spec.html#id2801681) exists in the target YAML file(s), set `documentMode: 'multi'`.
62
63### `exclude`
64
65Type: `String` | `Array[...String]`<br>
66Default: `null`
67
68A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.
69
70### `include`
71
72Type: `String` | `Array[...String]`<br>
73Default: `null`
74
75A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
76
77### `safe`
78
79Type: `Boolean`<br>
80Default: `true`
81
82If `true`, specifies that the data in the target YAML file(s) contain trusted data and should be loaded normally. If `false`, data is assumed to be untrusted and will be loaded using [safety methods](https://github.com/nodeca/js-yaml#safeload-string---options-).
83
84### `transform`
85
86Type: `Function`<br>
87Default: `undefined`
88
89A function which can optionally mutate parsed YAML. The function should return the mutated `object`, or `undefined` which will make no changes to the parsed YAML.
90
91```js
92yaml({
93 transform(data, filePath) {
94 if (Array.isArray(data) && filePath === './my-file.yml') {
95 return data.filter((character) => !character.batman);
96 }
97 }
98});
99```
100
101## Meta
102
103[CONTRIBUTING](/.github/CONTRIBUTING.md)
104
105[LICENSE (MIT)](/LICENSE)