Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fimars/c442bc83ebfea6fea028fa454b1947ed to your computer and use it in GitHub Desktop.
Save fimars/c442bc83ebfea6fea028fa454b1947ed to your computer and use it in GitHub Desktop.
Rollup Automatic External Dependencies

Hi!

This is an example of how to use [Rollup] with external dependencies, without hard-coding them.

It reads your installed NPM dependencies and treats them as external to Rollup. They still get bundled, but not as ES2015.

Make sure you have a .babelrc or a "babel":{} section in your package.json.

update

this fork for [email protected] in 2017/07/28

import path from 'path';
import fs from 'fs';
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
let pkg = JSON.parse(fs.readFileSync('./package.json')),
external = Object.keys(pkg.dependencies || {}),
babelRc = pkg.babel || JSON.parse(fs.readFileSync('./.babelrc'));
export default {
entry: pkg['jsnext:main'] || 'src/index.js',
dest: pkg.main,
sourceMap: path.resolve(pkg.main),
moduleName: pkg.amdName || pkg.name,
format: process.env.FORMAT || 'umd',
external,
plugins: [
babel({
babelrc: false,
...babelRc
}),
resolve({
jsnext: true,
main: true
}),
commonjs({
include: 'node_modules/**',
exclude: '**/*.css'
})
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment