# rollup-plugin-userscript-metadata

> A Rollup plugin that enables automatic generation of userscript metadata from JSON.

Latest version **2.0.1** (published 2023-10-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-userscript-metadata
pnpm add rollup-plugin-userscript-metadata
yarn add rollup-plugin-userscript-metadata
bun add rollup-plugin-userscript-metadata
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-10-21 |
| First published | 2023-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | GuangChen2333 |
| Maintainers | guangchen233 |
| Keywords | rollup, plugin, userscript |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-userscript-metadata
- Homepage: https://github.com/GuangChen2333/rollup-plugin-userscript-metadata
- Issues: https://github.com/GuangChen2333/rollup-plugin-userscript-metadata/issues
- npm.io page: https://npm.io/package/rollup-plugin-userscript-metadata

## 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

- 2.0.1 (latest) — 2023-10-21
- 2.0.0 — 2023-10-21

## README

# rollup-plugin-userscript-metadata

A Rollup.js plugin that enables automatic generation of userscript metadata from JSON.

## Quick Start

### Installation

#### npm

```shell
npm install --save-dev rollup-plugin-userscript-metadata
```

#### pnpm

```shell
pnpm install --save-dev rollup-plugin-userscript-metadata
```

#### yarn

```shell
yarn add --dev rollup-plugin-userscript-metadata
```

### Usage

Create a `rollup.config.mjs` configuration file and import the plugin:

```js
import metadata from 'rollup-plugin-userscript-metadata';

export default {
    input: 'src/index.js',
    output: {
        dir: 'output',
        format: 'iife'
    },
    plugins: [
        metadata({
            metadata: "src/metadata.json"
        })
    ]
};
```

Create a `metadata.json` metadata file like this:

```json
{
  "name": "my-plugin",
  "version": "1.0.0",
  "match": [
    "https://example.com/",
    "https://example.net/"
  ]
}
```

It will generate the metadata into your output file and **auto-align**.

```js
// ==UserScript==
// @name    my-plugin
// @version 1.0.0
// @match   https://example.com/
// @match   https://example.net/
// ==/UserScript==
```

#### Using with @rollup/plugin-terser

Here's how you can modify your `rollup.config.mjs` file to include the rollup-plugin-terser plugin and preserve 
the metadata:

```js
import metadata from "rollup-plugin-userscript-metadata"
import teaser from "@rollup/plugin-terser"

export default {
    input: 'src/index.js',
    output: {
        file: 'dist/index.min.js',
        format: 'iife'
    },
    plugins: [
        terser({
            format: {
                comments: [
                    "/\\/\\/ ==UserScript==\\n(?:\\/\\/ @[^\\n]+\\n)*\\/\\/ ==\\/UserScript==/\n/m"
                ]
            }
        }),
        metadata({
            metadata: "src/metadata.json"
        })
    ]
};
```

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