Skip to content

Instantly share code, notes, and snippets.

@calvinf calvinf/.babelrc.js
Last active Apr 24, 2018

What would you like to do?
Example Babel 7 config (Preact server-side, JSX, works with Jest)
// Example Babel 7 config
// Server-Side Preact Rendering
// with esm (most of the time)
// but Babel handles modules in test
// so Jest works
// target node version for Babel transpilation
const NODE_TARGET = 9;
// default settings for preset-env
const presetEnv = {
"targets": {
"node": NODE_TARGET,
// set modules to false for everything but test environment
// we normally let esm handle this,
// but Jest doesn't interact well with esm
if(process.env.NODE_ENV !== 'test') {
presetEnv.modules = false;
const presets = [
// use presetEnv settings determined above
["@babel/preset-env", presetEnv],
// React preset (set up for use with Preact on server-side)
["@babel/preset-react", {
"pragma": "h"
// export the Babel 7 config
module.exports = {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.