Created
December 4, 2016 17:41
-
-
Save yogurt1/574b852e8ec5a673726b87e2d47b6b38 to your computer and use it in GitHub Desktop.
my custom babel preset
This file contains 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
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