Last active
April 6, 2019 18:07
-
-
Save jmakeig/6337364e04993b1cac160c5ba112385b to your computer and use it in GitHub Desktop.
Rollup configuration to bundle a React app, declaring React as an external dependency
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 commonjs from 'rollup-plugin-commonjs'; | |
import replace from 'rollup-plugin-replace'; | |
export default { | |
/* https://engineering.mixmax.com/blog/rollup-externals */ | |
external: ['react', 'react-dom'], | |
/* | |
* Then in the host HTML page: | |
* <script crossorigin="anonymous" src="//cdn.jsdelivr.net/combine/npm/react@16.8.6/umd/react.development.min.js,npm/react-dom@16.8.6/umd/react-dom.development.min.js"></script> | |
*/ | |
input: 'src/index.js', | |
output: { | |
file: 'build/bundle.js', | |
format: 'iife', | |
sourcemap: true, | |
globals: { | |
react: 'React', | |
'react-dom': 'ReactDOM' | |
} | |
}, | |
plugins: [ | |
replace({ | |
'process.env.NODE_ENV': JSON.stringify('development') | |
}), | |
nodeResolve({ | |
browser: true, | |
jsnext: true, | |
main: true | |
}), | |
commonjs({ | |
include: 'node_modules/**' | |
}) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment