rollup-plugin-shim

1.0.0 • Public • Published

rollup-plugin-shim

NPM Package Build Status Coverage Status Commitizen friendly Dependencies

Plugin for rollup to provide a shim implementation for a module. Replaces required dependencies with the specified string instead, especially useful for shimming small dev-time APIs with a big footprint you don't want in production (like debug). For larger fully functional implementations that you want to use a file for you might want to consider the rollup-plugin-alias package instead.

Usage

Install

yarn add -D rollup-plugin-shim

Shim

src/main.js

import {writeFileSync} from 'fs'
import debug from 'debug'
import {bigFunction} from './local-dep'
 
const log = debug('mypackage:main')
// ...

rollup.config.js

import {join} from 'path'
import shim from 'rollup-plugin-shim'
 
export default {
  entry: 'src/main.js',
  plugins: [
    shim({
      // replace fs with a noop shim
      fs: `export function writeFileSync() { }`,
      // replace debug to return a noop function
      debug: `export default () => () => undefined`,
      // replace a local dependency with a noop
      // can also use './local-dep' as the key if that's the only way it's required
      [join(__dirname, 'src/local-dep')]: `export function bigFunction() { }`,
    }),
  ],
}

Readme

Keywords

none

Package Sidebar

Install

npm i rollup-plugin-shim

Weekly Downloads

2,635

Version

1.0.0

License

MIT

Last publish

Collaborators

  • patrickhulce