0.0.2 • Published 1 year ago

@thunderal/rollup-preprocess-plugin v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@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

  1. 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(),
      ],
    })
  2. 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}';`
    }
  3. Import generator file from another module (ex index.mjs):

    import {myHash} from 'hash-output.preprocess.mjs'
    
    console.log(myHash)
  4. Run rollup. Output will be:

    const myHash = "66631b816a5f33d6f...";
    
    console.log(myHash)
0.0.2

1 year ago

0.0.1

1 year ago