Skip to content

Instantly share code, notes, and snippets.

@yogurt1
Created December 4, 2016 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yogurt1/574b852e8ec5a673726b87e2d47b6b38 to your computer and use it in GitHub Desktop.
Save yogurt1/574b852e8ec5a673726b87e2d47b6b38 to your computer and use it in GitHub Desktop.
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