@thunderal/rollup-preprocess-plugin
v0.0.2
Published
Rollup plugin to make build-time generated modules
Downloads
1
Maintainers
Readme
@thunderal/rollup-preprocess-plugin
A Rollup plugin which allows you to tun build time code and include it's result to output bundle
Requirements
This plugin requires an LTS Node version (v14.0.0+) and Rollup v2.0.0+.
Install
Using npm:
npm install --save-dev @thunderal/rollup-preprocess-plugin
Using yarn:
yarn add -D @thunderal/rollup-preprocess-plugin
Usage
Create a
rollup.config.js
and import the plugin:import preprocess from '@thunderal/rollup-preprocess-plugin' const bundle = await rollup.rollup({ input: 'src/index.js', plugins: [ preprocess(), ], })
Create preprocessing file (ex
hash-output.preprocess.mjs
):import crypto from 'node:crypto' export default async function () { const hash = crypto.createHash('sha512') .update('super secret string. will not appear in result bundle') .digest() .toString('hex') return `export const myHash = '${hash}';` }
Import generator file from another module (ex
index.mjs
):import {myHash} from 'hash-output.preprocess.mjs' console.log(myHash)
Run rollup. Output will be:
const myHash = "66631b816a5f33d6f..."; console.log(myHash)