Skip to content

Instantly share code, notes, and snippets.

@calvinf
Last active April 24, 2018 02:51
Show Gist options
  • Save calvinf/e314719e3913bd46752c3dc78ccfac2e to your computer and use it in GitHub Desktop.
Save calvinf/e314719e3913bd46752c3dc78ccfac2e to your computer and use it in GitHub Desktop.
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 = {
presets,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment