1.0.1 • Published 5 years ago

rollup-plugin-redirect-files v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

rollup-plugin-redirect-files

A Rollup.js plugin for redirecting file imports using regular expressions.

Simpler than @rollup/plugin-alias for some use cases (especially redirecting file extensions for per-environment configuration files).

Installation

# yarn
yarn add rollup-plugin-redirect-files -D
 
# npm
npm i rollup-plugin-redirect-files -D

Usage

// rollup.config.js
import redirect from 'rollup-plugin-redirect-files';

export default {
    input: 'src/index.js',
    output: {
        file: 'dist/bundle.js',
        format: 'cjs'
    },
    plugins: {
        redirect({
            verbose: false, // output redirected files to console
            targets: [
                { from: '^(.*regex)[0-9]*(.*)$', to: '$1$2' }, // redirect a.regex23.b → a.regex.b
                { fromExt: 'env', toExt: 'prod' }, // redirect config.env.js → config.prod.js
                { fromExt: '.env', toExt: '.prod' }, // same thing, style choice
                { fromExt: 'env', toExt: process.env.BUILD } // run rollup with `--environment BUILD:prod`
            ]
        });
    }
};

Behind the scenes, fromExt/toExt are mapped to:

{
    from: `^(.*)\\${fromExt}(.*)$`,
    to: `$1${toExt}$2`
}
1.0.1

5 years ago

1.0.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago