Skip to content

Instantly share code, notes, and snippets.

@Andarist
Created February 16, 2018 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andarist/0d8efb15468bd9288ba1a7fa36f3e2a7 to your computer and use it in GitHub Desktop.
Save Andarist/0d8efb15468bd9288ba1a7fa36f3e2a7 to your computer and use it in GitHub Desktop.
Rollup example for @slorber
import nodeResolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import pkg from './package.json'
const mergeAll = objs => Object.assign({}, ...objs)
const commonPlugins = [
babel({
plugins: ['external-helpers'],
}),
]
const externals = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
]
const externalPattern = new RegExp(`^(${externals.join('|')})($|/)`)
const configBase = {
input: 'src/index.js',
external: externals.length === 0
? () => false
: id => externalPattern.test(id),
plugins: commonPlugins,
}
const webConfig = mergeAll([
configBase,
{ output: [{ file: pkg.module, format: 'es' }, { file: pkg.main, format: 'cjs' }] },
])
const rnConfig = mergeAll([
configBase,
{
output: { file: pkg['react-native'], format: 'cjs' },
plugins: commonPlugins.concat([
nodeResolve({ extensions: ['.native.js', '.js'] })
]),
},
])
export default [webConfig, rnConfig]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment