Created
June 3, 2019 05:18
-
-
Save kilgarenone/1d84d782f6be77341b648751a417ce9a to your computer and use it in GitHub Desktop.
babel loader webpack
This file contains hidden or 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
// this function will reside in the webpack.config.js. | |
// It accepts 'browserList' from 'browserList' key in 'package.json' | |
// therefore, no need for .babelrc file anymore | |
const configureBabelLoader = (browserList = []) => { | |
return { | |
test: /\.jsx?$/, | |
exclude: settings.babelLoaderConfig.exclude, | |
use: { | |
loader: "babel-loader", | |
options: { | |
cacheDirectory: true, | |
presets: [ | |
[ | |
"@babel/preset-env", | |
{ | |
exclude: ["transform-regenerator", "transform-async-to-generator"], // to make fast-async work | |
debug: !!isProduction, | |
modules: false, | |
corejs: 3, // the lastest corejs v3 | |
useBuiltIns: "usage", // only polyfill what you use | |
targets: { | |
browsers: browserList // this | |
} | |
} | |
] | |
], | |
plugins: [ | |
"@babel/plugin-transform-react-jsx", | |
"@babel/proposal-class-properties", | |
"@babel/proposal-object-rest-spread", | |
"@babel/plugin-syntax-dynamic-import", | |
"module:fast-async" // faster non-generator transformation for async/await | |
] | |
} | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment