babel plugins, presets and their configs per babel-preset-react-app

This commit is contained in:
Michael Bradley, Jr 2018-10-01 19:19:14 -05:00 committed by Pascal Precht
parent 6986d33da9
commit 8c6b26f311
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 52 additions and 2 deletions

View File

@ -110,12 +110,25 @@ const base = {
alias: embarkAliases alias: embarkAliases
} }
], ],
'babel-plugin-macros',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties', {
loose: true
}
],
[
'@babel/plugin-proposal-object-rest-spread', {
useBuiltIns: true
}
],
[ [
'@babel/plugin-transform-runtime', { '@babel/plugin-transform-runtime', {
corejs: 2, corejs: 2,
useESModules: true useESModules: true
} }
] ],
'@babel/plugin-syntax-dynamic-import'
].map(resolve), ].map(resolve),
presets: [ presets: [
[ [
@ -126,7 +139,11 @@ const base = {
} }
} }
], ],
'@babel/preset-react' [
'@babel/preset-react', {
useBuiltIns: true
}
]
].map(resolve) ].map(resolve)
} }
} }
@ -149,6 +166,13 @@ const base = {
profile: true, stats: 'verbose', profile: true, stats: 'verbose',
resolve: { resolve: {
alias: embarkAliases, alias: embarkAliases,
extensions: [
// webpack defaults
// see: https://webpack.js.org/configuration/resolve/#resolve-extensions
'.wasm', '.mjs', '.js', '.json',
// additional extensions
'.jsx'
],
modules: [ modules: [
...versions, ...versions,
'node_modules', 'node_modules',
@ -163,6 +187,20 @@ const base = {
} }
}; };
const baseBabelLoader = base.module.rules[3];
// Flow
// -----------------------------------------------------------------------------
// should be false in configs that have isTypeScriptEnabled = true
const isFlowEnabled = true;
if (isFlowEnabled) {
// position @babel/plugin-transform-flow-strip-types per babel-preset-react-app
baseBabelLoader.options.plugins.unshift(
require.resolve('@babel/plugin-transform-flow-strip-types')
);
}
// development config // development config
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -175,6 +213,10 @@ development.mode = 'development';
development.name = 'development'; development.name = 'development';
const devBabelLoader = development.module.rules[3]; const devBabelLoader = development.module.rules[3];
devBabelLoader.options.compact = false; devBabelLoader.options.compact = false;
// enable 'development' option for @babel/preset-react
const devPresetReact = devBabelLoader.options.presets[1];
const devPresetReactOptions = devPresetReact[1];
devPresetReactOptions.development = true;
// production config // production config
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -182,6 +224,14 @@ devBabelLoader.options.compact = false;
const production = cloneDeep(base); const production = cloneDeep(base);
production.mode = 'production'; production.mode = 'production';
production.name = 'production'; production.name = 'production';
const prodBabelLoader = production.module.rules[3];
// position babel-plugin-transform-react-remove-prop-types per babel-preset-react-app
prodBabelLoader.options.plugins.splice(prodBabelLoader.length - 1, 0, [
require.resolve('babel-plugin-transform-react-remove-prop-types'),
{
removeImport: true
}
]);
// compression of webpack's JS output not enabled by default // compression of webpack's JS output not enabled by default
// production.plugins.push(new CompressionPlugin()); // production.plugins.push(new CompressionPlugin());