Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// https://github.com/babel/babel/issues/10261
version: require('@babel/runtime/package.json').version,
regenerator: true,
// https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
// We should turn this on once the lowest version of Node LTS
// supports ES Modules.
useESModules,
// Undocumented option that lets us encapsulate our runtime, ensuring
// the correct version is used
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
absoluteRuntime: absoluteRuntimePath,
},
],
isEnvProduction && [
// Remove PropTypes from production build
require('babel-plugin-transform-react-remove-prop-types').default,
{
removeImport: true,
},
],
// Adds syntax support for import()
require('@babel/plugin-syntax-dynamic-import').default,
// Adds syntax support for optional chaining (?.)
require('@babel/plugin-proposal-optional-chaining').default,
// Adds syntax support for default value using ?? operator
require('@babel/plugin-proposal-nullish-coalescing-operator').default,
isEnvTest &&
// Transform dynamic import to require
require('babel-plugin-dynamic-import-node'),
].filter(Boolean),
overrides: [
isFlowEnabled && {
function plugins(api, opts = {}) {
return cleanList([
require('@babel/plugin-syntax-dynamic-import').default,
require('@babel/plugin-syntax-export-default-from').default,
require('@babel/plugin-syntax-export-namespace-from').default,
require('@babel/plugin-proposal-optional-chaining').default,
require('@babel/plugin-proposal-nullish-coalescing-operator').default,
[require('@babel/plugin-proposal-decorators').default, {legacy: true}],
[require('@babel/plugin-proposal-class-properties').default, {loose: true}],
[
require('babel-plugin-transform-react-remove-prop-types').default,
{
wrap: true
}
],
[
require('@babel/plugin-proposal-object-rest-spread').default,
{useBuiltIns: true} // asume Object.assign is available by browser or polyfill
],
[
require('@babel/plugin-transform-runtime').default,
{
corejs: false,
useESModules: true,
regenerator: true
}
]
corejs: false,
helpers: areHelpersEnabled,
regenerator: true,
// https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
// We should turn this on once the lowest version of Node LTS
// supports ES Modules.
useESModules,
// Undocumented option that lets us encapsulate our runtime, ensuring
// the correct version is used
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
absoluteRuntime: absoluteRuntimePath,
},
],
isEnvProduction && [
// Remove PropTypes from production build
require('babel-plugin-transform-react-remove-prop-types').default,
{
removeImport: true,
},
],
// Adds syntax support for import()
require('@babel/plugin-syntax-dynamic-import').default,
isEnvTest &&
// Transform dynamic import to require
require('babel-plugin-dynamic-import-node'),
].filter(Boolean),
overrides: [
isFlowEnabled && {
exclude: /\.tsx?$/,
plugins: [require('@babel/plugin-transform-flow-strip-types').default],
},
isTypeScriptEnabled && {
{
useBuiltIns: true,
},
],
// Polyfills the runtime needed for async/await and generators
!isEnvNode && [
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
polyfill: false,
regenerator: true,
},
],
isEnvProduction && [
// Remove PropTypes from production build
require('babel-plugin-transform-react-remove-prop-types').default,
{
removeImport: true,
},
],
// function* () { yield 42; yield 43; }
!(isEnvTest || isEnvNode) && [
require('@babel/plugin-transform-regenerator').default,
{
// Async functions are converted to generators by @babel/preset-env
async: false,
},
],
// Adds syntax support for import()
require('@babel/plugin-syntax-dynamic-import').default,
(isEnvTest || isEnvNode) &&
// Transform dynamic import to require
require('@babel/plugin-transform-destructuring'),
[
require('@babel/plugin-proposal-class-properties'),
{
loose: true,
}
],
[
require('@babel/plugin-proposal-object-rest-spread'),
{
useBuiltIns: true,
}
],
!devMode && [
// Remove PropTypes from production build
require('babel-plugin-transform-react-remove-prop-types').default,
{
removeImport: true,
},
],
].filter(it => it)
}
},
{
test: /\.less$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'less-loader',
options: {
noIeCompat: false
corejs: false,
helpers: areHelpersEnabled,
regenerator: true,
// https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
// We should turn this on once the lowest version of Node LTS
// supports ES Modules.
useESModules,
// Undocumented option that lets us encapsulate our runtime, ensuring
// the correct version is used
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
absoluteRuntime: absoluteRuntimePath,
},
],
isEnvProduction && [
// Remove PropTypes from production build
require('babel-plugin-transform-react-remove-prop-types').default,
{
removeImport: true,
},
],
// Adds syntax support for import()
require('@babel/plugin-syntax-dynamic-import').default,
isEnvTest &&
// Transform dynamic import to require
require('babel-plugin-dynamic-import-node'),
].filter(Boolean),
overrides: [
isFlowEnabled && {
exclude: /\.tsx?$/,
plugins: [require('@babel/plugin-transform-flow-strip-types').default],
},
isTypeScriptEnabled && {
[
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true,
corejs: false
}
],
[
require('@babel/plugin-transform-regenerator').default,
{
async: false
}
],
isProductionEnv && [
require('babel-plugin-transform-react-remove-prop-types').default,
{
removeImport: true
}
]
].filter(Boolean)
}
}
[
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true,
corejs: false
}
],
[
require('@babel/plugin-transform-regenerator').default,
{
async: false
}
],
isProductionEnv && [
require('babel-plugin-transform-react-remove-prop-types').default,
{
removeImport: true
}
]
].filter(Boolean)
}
}
module.exports = function preset (context, opts = {}) {
const production = Boolean(opts.production || process.env.NODE_ENV === 'production')
return {
plugins: [
require('babel-plugin-transform-react-jsx'),
require('babel-plugin-syntax-jsx'),
require('babel-plugin-transform-react-display-name'),
!production && require('babel-plugin-transform-react-jsx-source'),
!production && require('babel-plugin-transform-react-jsx-self'),
production && require('babel-plugin-transform-react-inline-elements'),
production && require('babel-plugin-transform-react-constant-elements'),
production && require('babel-plugin-transform-react-remove-prop-types').default,
production && require('babel-plugin-transform-react-pure-class-to-function'),
].filter(Boolean)
}
}