Created
June 26, 2020 08:47
-
-
Save chmelevskij/1dd9f241c660c3abadbf0f6260d3a4ad to your computer and use it in GitHub Desktop.
Basic config to build differential react build
This file contains hidden or 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 babel from '@rollup/plugin-babel'; | |
import commonjs from '@rollup/plugin-commonjs'; | |
import styles from 'rollup-plugin-styles'; | |
import resolve from '@rollup/plugin-node-resolve'; | |
import url from '@rollup/plugin-url'; | |
import svgr from '@svgr/rollup'; | |
import replace from '@rollup/plugin-replace'; | |
import { terser } from 'rollup-plugin-terser'; | |
import json from '@rollup/plugin-json' | |
function indexPlugin() { | |
return { | |
name: 'index', | |
generateBundle(options, bundle) { | |
// dunno if it's always first, but looks like it | |
const [entry] = Object.keys(bundle); | |
console.log(`Writing entry: ${entry}`); | |
this.emitFile({ | |
type: 'asset', | |
fileName: 'index.html', | |
source: ` | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Forms</title> | |
</head> | |
<body> | |
<div id="react-root"></div> | |
<script type="module" src="index.mjs"></script> | |
<script nomodule src="index.js"></script> | |
</body> | |
</html> | |
`, | |
}); | |
}, | |
}; | |
} | |
export default { | |
input: 'client/index.jsx', | |
output: [ | |
{ | |
file: 'static/index.js', | |
format: 'umd', | |
sourcemap: true, | |
}, | |
{ | |
file: 'static/index.mjs', | |
format: 'es', | |
sourcemap: true, | |
}, | |
], | |
plugins: [ | |
replace({ | |
'process.env.NODE_ENV': JSON.stringify('development'), | |
}), | |
json(), | |
styles(), | |
url(), | |
svgr(), | |
resolve(), | |
commonjs({ include: 'node_modules/**' }), | |
babel({ | |
presets: ['@babel/preset-react'], | |
exclude: 'node_modules/**', | |
babelHelpers: 'bundled', | |
}), | |
terser(), | |
// this will run twice, but it's fine | |
indexPlugin(), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment