0.1.2 • Published 7 years ago

babelrc-targeted-rollup v0.1.2

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

babelrc-targeted-rollup

Builds a babel configuration for rollup with specific targets from babel-preset-env.

Installation

yarn add babelrc-targeted-rollup --dev

Usage

Create a .babelrc containing the env preset.

{
    "presets": [
        ["env", {
            "targets": {
                "node"     : 6,
                "browsers" : "Last 2 versions" 
            }
        }]
    ]
}

Then, in your rollup.config.js:

import babelrc from 'babelrc-targeted-rollup';
import babel   from 'rollup-plugin-babel';

const baseOptions = {
    input    : 'src/my-package.js',
    external : ['lodash'],
    globals  : {
        'lodash': '_'
    }
};

const targets = [
    {
        output: {
            file   : 'dist/my-package.js',
            format : 'umd',
            name   : 'MyPackage'
        },
        plugins: [
            babel(babelrc('browsers'))
        ]
    },
    {
        output: {
            file   : 'dist/my-package.es.js',
            format : 'es'
        },
        plugins : [
            babel(babelrc('node'))
        ]
    }
];
export default targets.map(targetOptions => (
    Object.assign({}, baseOptions, targetOptions)
));

Options

You can pass the same options as for babelrc-rollup plus:

targets (default: [])

The babel-preset-env targets you want to have inside the returned babel configuration.