# rollup-plugin-data-files

> Bundle web workers that work in nodejs and the browser, without a separate build target.

Latest version **0.1.0** (published 2021-01-20) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-data-files
pnpm add rollup-plugin-data-files
yarn add rollup-plugin-data-files
bun add rollup-plugin-data-files
```

## 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.1.0 |
| Published | 2021-01-20 |
| First published | 2021-01-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Brandon Casey |
| Maintainers | brandonocasey |
| Keywords | rollup, rollup-plugin |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-data-files
- Repository: https://github.com/brandonocasey/rollup-plugin-data-files
- Issues: https://github.com/brandonocasey/rollup-plugin-data-files/issues
- npm.io page: https://npm.io/package/rollup-plugin-data-files

## Dependencies (2)

- [matched](https://npm.io/package/matched.md) ^5.0.1
- [@rollup/pluginutils](https://npm.io/package/@rollup/pluginutils.md) ^4.1.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2021-01-20
- 0.0.1 — 2021-01-20

## README

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Install](#install)
- [Requirements](#requirements)
- [Usage](#usage)
- [Options](#options)
  - [<key>](#key)
    - [<key>.transform](#keytransform)
      - [As a string](#as-a-string)
      - [As a function](#as-a-function)
    - [<key>.include](#keyinclude)
    - [<key>.exclude](#keyexclude)
    - [<key>.extensions](#keyextensions)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Install
```sh
npm i -D rollup-plugin-data-files
```

## Requirements
* rollup v2.29.0 or later to allow for the addition of a file in a globbed directory to rebuild in this plugin
## Usage
include rollup-plugin-data-files in your rollup plugins array for a build:
```js
const dataFiles = require('rollup-plugin-data-files');

...
plugins: [
  dataFiles({
    something: {
      // files to include when data-files!something is imported
      include: 'test/fixtures/**',
      // these are binary files, give me a uint8array
      transform: 'binary'
    }
  })
]
...
```

When you want to include the data file use `data-files!<configured-key>` so for our example that would be:
```js
import something from "data-files!something";

// get and console.log the uint8 array for some-file-name.jpg
console.log(something['some-file-name.jpg']());
```

Also know that you can find your file in the output bundle by searching for `rollup-plugin-data-files` and finding your key.

## Options
### <key>
The main Object that is passed to `rollup-plugin-data-files` takes keys that will refer to the reference id of your data file. The value for that key is the configuration for it's build. Those options are defined below.


#### <key>.transform
> Default: 'binary'

##### As a string
transform can be set 4 possible string values:
1. 'binary' exports an object with functions that return a `Uint8Array` of file contents.
2. 'string' exports an object with functions that will return a string of the file contents.
3. 'json' exports an object with function that will return a `JSON.parse` of the file contents.
4. 'js' exports an object with function that will return a the result of requiring the files specified.

##### As a function
Using transform as a function
```js
transform: function(key, files) {
  let output = 'module.exports = {\n'

  files.forEach(function({filepath, contents}) {
    // filepath is a string, contents is a buffer.
    output += `'${filepath}': () => '${contents.toString()}',\n`
  });

  output += '};\n';
  return output;
}

```

#### <key>.include
> Note: if you want the addition of files to trigger a rebuild, make sure you are using a glob or directly pass in a directory here.
A file, glob or an array of files/globs to include in your data-file.

#### <key>.exclude
A file, glob or an array of files/globs to exclude from your data-file.

#### <key>.extensions
> Default: true

Should file extensions be included in the resulting object generated by string transform.

example for foo.txt with extensions true:
```js
{
  'foo.txt': () => 'hello world'
}
```

example for foo.txt with extensions false:
```js
{
  'foo': () => 'hello world'
}
```

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