forked from RedHatInsights/frontend-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
120 lines (114 loc) · 3.69 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require.extensions['.css'] = () => undefined;
const path = require('path');
const glob = require('glob');
const mapper = {
TextVariants: 'Text',
ButtonVariant: 'Button',
PaginationVariant: 'Pagination',
SelectVariant: 'selectConstants',
EmptyStateVariant: 'EmptyState',
DropdownPosition: 'dropdownConstants',
TextListVariants: 'TextList',
TextListItemVariants: 'TextListItem',
ClipboardCopyVariant: 'ClipboardCopy',
TooltipPosition: 'Tooltip'
};
const iconMapper = {
AnsibeTowerIcon: 'ansibeTower-icon',
ChartSpikeIcon: 'chartSpike-icon',
CloudServerIcon: 'cloudServer-icon'
};
const createPfReactTransform = (env) => [
'transform-imports',
{
'@patternfly/react-core': {
transform: (importName) => {
let res;
const pathname = path.resolve(__dirname, `node_modules/@patternfly/react-core/dist/${env}/**/${mapper[importName] || importName}.js`);
const files = glob.sync(pathname);
if (files.length > 0) {
res = files[0];
} else {
throw new Error(`File with importName ${importName} does not exist. Glob path: ${pathname}`);
}
res = res.split('/node_modules/').pop();
res = res.replace(/^\//, '');
return res;
},
preventFullImport: false,
skipDefaultConversion: true
},
'@patternfly/react-icons': {
transform: (importName) =>
`@patternfly/react-icons/dist/${env}/icons/${iconMapper[importName] || importName
.split(/(?=[A-Z])/)
.join('-')
.toLowerCase()}`,
preventFullImport: true
},
'patternfly-react': {
transform: (importName) => {
let res;
const files = glob.sync(path.resolve(__dirname, `../../node_modules/patternfly-react/dist/${env}/**/${importName}.js`));
if (files.length > 0) {
res = files[0];
} else {
throw new Error(`File with importName ${importName} does not exist`);
}
res = res.split('/node_modules/').pop();
res = res.replace(/^\//, '');
return res;
},
preventFullImport: false,
skipDefaultConversion: false
}
},
`pf-react-${env}`
];
module.exports = {
presets: [
[
'@babel/env',
{
targets: '> 0.25%, not dead'
}
],
'@babel/preset-react'
],
plugins: [
[
'@babel/plugin-proposal-decorators',
{
legacy: true
}
],
'@babel/plugin-transform-runtime',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-object-rest-spread',
'babel-plugin-lodash',
'@babel/plugin-transform-react-display-name',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining'
],
env: {
cjs: {
presets: [ [ '@babel/preset-env', { modules: 'commonjs' }] ],
plugins: [
'./plugins/transform-scss-plugin',
createPfReactTransform('js')
]
},
esm: {
presets: [ [ '@babel/preset-env', { modules: false }] ],
plugins: [
[
'./plugins/transform-scss-plugin',
{
esm: true
}
],
createPfReactTransform('esm')
]
}
}
};