Skip to content

Instantly share code, notes, and snippets.

@gecugamo
Created January 9, 2023 18:54
Show Gist options
  • Save gecugamo/a0532276ab76045dd4c259b1f98e00c3 to your computer and use it in GitHub Desktop.
Save gecugamo/a0532276ab76045dd4c259b1f98e00c3 to your computer and use it in GitHub Desktop.
Ex Babel Config
module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')
if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}
return {
assumptions: {
setPublicClassFields: true
},
presets: [
isTestEnv && [
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
'@babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
],
['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'@babel/plugin-transform-destructuring',
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true } ],
[
'@babel/plugin-proposal-class-properties'
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'@babel/plugin-proposal-private-methods'
],
[
'@babel/plugin-proposal-private-property-in-object'
],
[
'@babel/plugin-transform-runtime',
{
helpers: false
}
],
[
'@babel/plugin-transform-regenerator',
{
async: false
}
]
].filter(Boolean)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment