Nonstick Pancake Maker

    rollup-plugin-virtual-alias

    1.0.1 • Public • Published

    rollup-plugin-virtual-alias

    Alias dependencies using virtual modules.

    Usage

    Suppose you are working with an existing codebase and want to substitute one API compatible dependency for another. In my case, I wanted to try preact-compat in place of react.

    // src.main.js
    import React from 'react';
    import ReactDOM from 'react-dom';
    // rollup.config.js
    import virtual_alias from 'rollup-plugin-virtual-alias';
     
    export default {
      entry: 'src/main.js',
      // ...
      plugins: [
        virtual_alias({
          'react': 'preact-compat',
          'react-dom': 'preact-compat',
        }),
      ]
    };

    As with rollup-plugin-virtual, use this plugin before other plugins like rollup-plugin-node-resolve or rollup-plugin-commonjs.

    Implementation

    This package translates each pair in the mapping passed to virtual_alias() into a module string for rollup-plugin-virtual. So the following:

    import virtual_alias from 'rollup-plugin-virtual-alias';
     
        // ...
        virtual_alias({
          'react': 'preact-compat',
          'react-dom': 'preact-compat',
        }),
        // ...
     

    Is equivalent to:

    import virtual from 'rollup-plugin-virtual';
     
        // ...
        virtual({
          'react': `
              export * from "preact-compat"
              export {default} from "preact-compat"
              `,
     
          'react-dom': `
              export * from "preact-compat"
              export {default} from "preact-compat"
              `,
        })
        // ...

    License

    This package was inspired and heavily derived from Rich-Harris's work in rollup/rollup-plugin-virtual.

    MIT

    Install

    npm i rollup-plugin-virtual-alias

    DownloadsWeekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • shanewholloway