docbrown/babel.config.js
Daniel Uber 69a03c8b07
Add explicit loose configuration for babel plugins (#14048)
* Add explicit loose configuration for babel private-property plugin

Squelch this warning that happens a few dozen times during CI by
following the instructions:

Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-proposal-private-property-in-object since the "loose" mode option was set to "true" for @babel/plugin-proposal-private-methods.

The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding

	["@babel/plugin-proposal-private-property-in-object", { "loose": true }]

to the "plugins" section of your Babel config.

* Use spaces instead of tabs

This won't affect the test.

* Make all the other "implied loose" options loose, too.

This now squelches the warnings, and webpacker can compile without failing.

* Collect common option "loose: true" to preset env

Rather than 3 overrides to bring these inline, move to the shared options.

* Revert "Collect common option "loose: true" to preset env"

This reverts commit ca3d09ba6a47e03dbfb5f6108fcbc7f19b5a457b.
2021-06-23 13:57:51 -05:00

74 lines
1.8 KiB
JavaScript

/* eslint-env node */
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 {
presets: [
(isProductionEnv || isDevelopmentEnv || isTestEnv) && [
'@babel/preset-env',
{
modules: false,
targets: { browsers: '> 1%' },
useBuiltIns: 'entry',
corejs: { version: 3, proposals: false },
exclude: ['transform-regenerator'],
bugfixes: true,
forceAllTransforms: true,
},
'preact',
],
].filter(Boolean),
plugins: [
'@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
isTestEnv && '@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
spec: true,
loose: true,
},
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true,
},
],
[
'@babel/plugin-proposal-private-property-in-object',
{
loose: true,
}
],
[
'@babel/plugin-proposal-private-methods',
{
loose: true,
}
],
[
'@babel/plugin-transform-react-jsx',
{
pragma: 'h',
},
],
].filter(Boolean),
};
};