# rollup-plugin-import-yaml

> import yaml files inside code files. Types are generated dynamically for TS.

Latest version **0.0.6** (published 2023-06-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-import-yaml
pnpm add rollup-plugin-import-yaml
yarn add rollup-plugin-import-yaml
bun add rollup-plugin-import-yaml
```

Provides the command `yml-dec-gen`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2023-06-28 |
| First published | 2023-06-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Hussain Taj |
| Maintainers | hussaintaj |
| Keywords | vite-plugin, rollup-plugin, yaml, import, vite, rollup, typescript, ts |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-import-yaml
- Repository: https://github.com/HussainTaj-W/rollup-plugin-import-yaml
- Homepage: https://github.com/HussainTaj-W/rollup-plugin-import-yaml#readme
- Issues: https://github.com/HussainTaj-W/rollup-plugin-import-yaml/issues
- npm.io page: https://npm.io/package/rollup-plugin-import-yaml

## Dependencies (2)

- [glob](https://npm.io/package/glob.md) ^10.2.6
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 0.0.6 (latest) — 2023-06-28
- 0.0.5 — 2023-06-07
- 0.0.4 — 2023-06-07
- 0.0.3 — 2023-06-07
- 0.0.2 — 2023-06-04
- 0.0.1 — 2023-06-04

## README

# rollup-plugin-import-yaml

Import YAML files into code as JS or TS objects. For TS, types for each YAML file is generated dynamically.

## Usage

### Add Dependency

```bash
npm i -D rollup-plugin-import-yaml
```

### (Javascript) Configure Plugin

```js
import importYaml from "rollup-plugin-import-yaml";

export default defineConfig(({ mode }) => {
  return {
    plugins: [importYaml()],
  };
});
```

### (Typescript) Configure Plugin

For typescript, type declarations are generated for each YAML file and added to `<filename>.yml.d.ts` file.

#### vite.config.ts

```ts
import importYaml from "rollup-plugin-import-yaml";

export default defineConfig(({ mode }) => {
  return {
    plugins: [
      importYaml({
        isTS: true,
      }),
    ],
  };
});
```

#### tsconfig.json

```json
{
  "compilerOptions": {
    "types": ["rollup-plugin-import-yaml/src/types"]
  }
}
```

### CLI / Generating Types Separately / Existing Projects

If you need to generate types manually for some reason (like integrating this plugin into an existing project), you can run the `yml-dec-gen` cli command.

#### Install Dependency Globally

```bash
npm i -g rollup-plugin-import-yaml
```

Then in your project directory run.

```bash
yml-dec-gen
```

## Referencing other files

This plugin has a special feature that lets you include yaml files inside other
yaml files. This feature is disabled by default, to enable it use:

```ts
import importYaml from "rollup-plugin-import-yaml";

export default defineConfig(({ mode }) => {
  return {
    plugins: [
      importYaml({
        isTS: true,
        shouldFollowReferences: true,
      }),
    ],
  };
});
```

### Example

> Input (data.yml)

```yml
list: (( include ./list.yml ))

object: (( include ./object.yml ))
```

> list.yml

```yml
- a
- b
```

> object.yml

```yml
abc: abc
```

> Output (data.yml) when imported

```yml
list:
  - a
  - b

object:
  abc: abc
```

---
_Source: https://npm.io/package/rollup-plugin-import-yaml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
