forked from e621ng/e621ng

Loose does super dumb shit like converts spread operators to [].concat() which is broken, incorrect, and not at all helpful. Because this was forced in their base preset, it would break all kinds of things that shouldn't have broken, and it would ignore the project config explicitly. This seems to fix the vast majority of the JS on the site, and the generated code makes a lot more sense now.
55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
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')
|
|
const { moduleExists } = require('@rails/webpacker')
|
|
|
|
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: [
|
|
isTestEnv && ['@babel/preset-env', { targets: { node: 'current' } }],
|
|
(isProductionEnv || isDevelopmentEnv) && [
|
|
'@babel/preset-env',
|
|
{
|
|
useBuiltIns: 'entry',
|
|
corejs: '3.8',
|
|
modules: 'auto',
|
|
bugfixes: true,
|
|
exclude: ['transform-typeof-symbol']
|
|
}
|
|
],
|
|
moduleExists('@babel/preset-typescript') && [
|
|
'@babel/preset-typescript',
|
|
{ allExtensions: true, isTSX: true }
|
|
],
|
|
moduleExists('@babel/preset-react') && [
|
|
'@babel/preset-react',
|
|
{
|
|
development: isDevelopmentEnv || isTestEnv,
|
|
useBuiltIns: true
|
|
}
|
|
]
|
|
].filter(Boolean),
|
|
plugins: [
|
|
['@babel/plugin-proposal-class-properties', { loose: true }],
|
|
['@babel/plugin-transform-runtime', { helpers: false }],
|
|
isProductionEnv &&
|
|
moduleExists('babel-plugin-transform-react-remove-prop-types') && [
|
|
'babel-plugin-transform-react-remove-prop-types',
|
|
{ removeImport: true }
|
|
]
|
|
].filter(Boolean)
|
|
}
|
|
}
|