-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
93 lines (89 loc) · 3 KB
/
babel.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const loadConfig = require('@instructure/config-loader')
module.exports = function babel(api) {
const isProduction = api.env('production')
/*
const presets = [
'@babel/preset-typescript',
[ '@babel/preset-env', {
targets: {
browsers: loadConfig(
'browserslist',
require('@instructure/browserslist-config-instui')
)
},
useBuiltIns: 'entry',
corejs: 3,
modules: false,
//debug: true, // un-comment if you want to see what browsers are being targeted and what plugins that means it will activate
exclude: ['transform-typeof-symbol'],
// have to include this plugin because babel-loader can't handle the `??` operator
include: ['proposal-nullish-coalescing-operator']
} ],
[ '@babel/preset-react', { useBuiltIns: true } ]
]
*/
const presets = [ require('@instructure/ui-babel-preset') ]
const plugins = []
/*
plugins.push([
require('@instructure/babel-plugin-transform-imports'),
{
'(@instructure/ui-[^(/|\\s)]+)$': {
// eslint-disable-line no-useless-escape
transform: (importName, matches) => {
const ignore = [
'@instructure/ui-test-queries',
'@instructure/ui-test-sandbox',
'@instructure/ui-test-utils'
]
if (!matches || !matches[1] || ignore.includes(matches[1])) return
return `${matches[1]}/lib/${importName}`
}
},
// Convert any es imports to lib imports
'(@instructure/ui-[^(/|\\s)]+/es/[^\\s]+)$': {
// eslint-disable-line no-useless-escape
transform: (importName, matches) => {
if (!matches || !matches[1]) return
return matches[1].replace(new RegExp('/es/'), '/lib/')
}
},
}
])
let babelHelperVersion = {}
try {
// eslint-disable-next-line import/no-extraneous-dependencies
const version = require('@babel/helpers/package.json').version
babelHelperVersion.version = version
} catch (e) {
// if something goes wrong, continue and don't try to explicitly set a helper version
}
plugins.push(
require('babel-plugin-macros'),
require('@babel/plugin-transform-destructuring').default,
[require('@babel/plugin-proposal-decorators').default, { legacy: true }], // must run before plugins that set displayName!
require('@instructure/ui-babel-preset/lib/babel-plugin-add-displayname-for-react.js'),
[
require('@babel/plugin-proposal-class-properties').default,
{ loose: true }
],
require('@babel/plugin-proposal-export-default-from').default,
[
require('@babel/plugin-transform-runtime').default,
{
...babelHelperVersion,
corejs: false,
regenerator: true,
helpers: true,
useESModules: false,
}
],
require('@babel/plugin-syntax-dynamic-import').default,
require('babel-plugin-transform-undefined-to-void')
)
*/
if (!isProduction) {
plugins.push('react-refresh/babel')
}
return { presets, plugins }
}