Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
my custom babel preset
const preset = buildPreset()
Object.defineProperty(preset, "buildPreset", {
configurable: true,
writable: true,
enumerable: false,
value: buildPreset
})
module.exports = preset
function buildPreset(opts = {}) {
const {env = "node"} = opts;
const browser = env === "browser"
const node = env === "node"
const isProduction = process.env.NODE_ENV === 'production'
const presets = [
["env", {
modules: !browser && "commonjs",
loose: true,
targets: browser ? {
"chrome": 55
} : {
node: "current"
}
}],
"react"
]
const plugins = [
["transform-async-to-module-method", {
module: "bluebird-co",
method: "coroutine"
}],
"transform-class-properties",
"transform-decorators-legacy",
["transform-runtime"],
["transform-object-rest-spread", {
useBuiltIns: true
}],
!browser && ["system-import-transformer", {
modules: "commonjs"
}],
(browser && !isProduction) && "react-hot-loader/babel"
]
if (browser && isProduction) {
presets.push(
"babili",
"react-optimize"
)
plugins.push(
"minify-empty-function",
"transform-remove-console",
"transform-remove-debugger",
"transform-node-env-inline",
"transform-inline-environment-variables",
"transform-react-inline-elements"
)
}
return {
presets: presets.filter(Boolean),
plugins: plugins.filter(Boolean),
}
}
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.