Skip to content

Instantly share code, notes, and snippets.

@miaulightouch
Created August 17, 2018 15:29
Show Gist options
  • Save miaulightouch/3b2488d3b7a7b7c77ae0180a69b58786 to your computer and use it in GitHub Desktop.
Save miaulightouch/3b2488d3b7a7b7c77ae0180a69b58786 to your computer and use it in GitHub Desktop.
import path from 'path'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'
import { dependencies } from './package.json'
const esm = process.env.BABEL_ENV === 'esm'
function genConf (input) {
const basename = path.basename(input).split('.')[0]
return {
input,
// bundle deps into es modules
external: ['os', 'util', 'tty'].concat(esm ? [] : Object.keys(dependencies)),
plugins: [
resolve(),
commonjs(),
babel({
exclude: 'node_modules/**', // only transpile our source code
runtimeHelpers: true
})
],
// FIXME: do not use mjs extension until other bundler supported.
output: {
format: esm ? 'esm' : 'cjs',
file: `${basename}.js`,
dir: esm ? 'esm' : 'lib'
}
}
}
const entry = [
'src/browser.js',
'src/node.js',
'src/index.js'
]
export default entry.map(genConf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment