Skip to content

Instantly share code, notes, and snippets.

@kilgarenone
Created June 3, 2019 05:18
Show Gist options
  • Save kilgarenone/1d84d782f6be77341b648751a417ce9a to your computer and use it in GitHub Desktop.
Save kilgarenone/1d84d782f6be77341b648751a417ce9a to your computer and use it in GitHub Desktop.
babel loader webpack
// 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