Created
February 16, 2018 13:09
-
-
Save Andarist/0d8efb15468bd9288ba1a7fa36f3e2a7 to your computer and use it in GitHub Desktop.
Rollup example for @slorber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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