rollup-plugin-userscript-metablock
v0.7.1
Published
Transform config file to userscript metablock and append on
Readme
rollup-plugin-userscript-metablock
Transform json file to userscript metablock and append on.
Metakeys documents:
Installation
npm install --save-dev rollup-plugin-userscript-metablockUsage
simplest
import metablock from 'rollup-plugin-userscript-metablock';
export default {
input: 'main.js',
output: {
file: 'bundle.user.js',
format: 'esm'
},
plugins: [metablock()],
};common
import metablock from 'rollup-plugin-userscript-metablock';
import pkg from './package.json' with { type: 'json' };
export default {
input: 'main.js',
output: {
file: 'bundle.user.js',
format: 'esm'
},
plugins: [metablock({
file: './meta.json',
override: {
name: pkg.name,
version: pkg.version,
description: pkg.description,
homepage: pkg.homepage,
author: pkg.author,
license: pkg.license,
}
})],
};You can find the options detail here, and meta details here.
JSON Schema
JSON metadata files can reference the schema shipped with this package for editor completion and validation. The file itself is the metadata object, so its top-level properties are metakeys without the leading @:
{
"$schema": "https://cdn.jsdelivr.net/npm/rollup-plugin-userscript-metablock@latest/userscript-metadata.schema.json",
"name": "My userscript",
"match": "https://example.com/*",
"grant": "none"
}The same schema is also available from UNPKG. The plugin ignores the $schema property when it renders the metablock.
JavaScript metadata files
The file option also accepts .js, .mjs, and .cjs modules. Use defineMetadata to get IDE auto-completion:
// metablock.mjs
import { defineMetadata } from 'rollup-plugin-userscript-metablock';
export default defineMetadata({
name: 'My userscript',
grant: 'none',
});// metablock.cjs
const { defineMetadata } = require('rollup-plugin-userscript-metablock');
module.exports = defineMetadata({
name: 'My userscript',
grant: 'none',
});Rolldown
This plugin also works with Rolldown. See the complete Rolldown example.
Other
- If no grant, use
@grant noneexplicitly
License
MIT
