forked from RedHatInsights/insights-advisor-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
140 lines (132 loc) · 3.88 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require.extensions['.css'] = () => undefined;
const path = require('path');
const glob = require('glob');
/**
* We require a mapper for some PF modules because the modle export names do not match their location
*/
const mapper = {
TextVariants: 'Text',
EmptyStateVariant: 'EmptyState',
PaginationVariant: 'Pagination',
SelectVariant: 'selectConstants',
DropdownPosition: 'dropdownConstants',
TextListVariants: 'TextList',
TextListItemVariants: 'TextListItem',
ClipboardCopyVariant: 'ClipboardCopy',
TooltipPosition: 'Tooltip',
};
const IconMapper = {
AnsibeTowerIcon: 'ansibeTower-icon',
};
const FECMapper = {
SkeletonSize: 'Skeleton',
PageHeaderTitle: 'PageHeader',
conditionalFilterType: 'ConditionalFilter',
};
const NotificationMapper = {
REMOVE_NOTIFICATION: 'actionTypes',
ADD_NOTIFICATION: 'actionTypes',
NotificationsPortal: 'NotificationPortal',
addNotification: 'actions',
};
/**
* These two plugins will replace all replative imports with absolute import paths to the commonJS version of asset
* PF esm build is broken, it points to commonJS files internaly
* There fore its better to use commonJS version of the build to avoid duplicate cjs/esm variants of components
* After its fixed in PF we can swap to using esm build
*/
const patternflyTransformImports = (env) => [
'transform-imports',
{
'@patternfly/react-table': {
skipDefaultConversion: true,
transform: `@patternfly/react-table/dist/${env}`,
},
'@patternfly/react-core': {
transform: (importName) => {
let res;
const files = glob.sync(
path.resolve(
__dirname,
`./node_modules/@patternfly/react-core/dist/${env}/**/${
mapper[importName] || importName
}.js`
)
);
if (files.length > 0) {
res = files[0];
} else {
throw `File with importName ${importName} does not exist`;
}
res = res.replace(path.resolve(__dirname, './node_modules/'), '');
res = res.replace(/^\//, '');
return res;
},
preventFullImport: true,
skipDefaultConversion: true,
},
'@patternfly/react-icons': {
transform: (importName) =>
`@patternfly/react-icons/dist/${env}/icons/${
IconMapper[importName] ||
importName
.split(/(?=[A-Z])/)
.join('-')
.toLowerCase()
}.js`,
preventFullImport: true,
},
},
'patternfly-react',
];
const fecTransformImports = (env) => [
'transform-imports',
{
'@redhat-cloud-services/frontend-components': {
transform: (importName) =>
`@redhat-cloud-services/frontend-components/components/${env}/${
FECMapper[importName] || importName
}.js`,
preventFullImport: false,
skipDefaultConversion: true,
},
'@redhat-cloud-services/frontend-components-notifications': {
transform: (importName) =>
`@redhat-cloud-services/frontend-components-notifications/${env}/${
NotificationMapper[importName] || importName
}.js`,
preventFullImport: true,
},
},
'frontend-components',
];
module.exports = {
presets: ['@babel/env', '@babel/react', '@babel/flow'],
plugins: [
[
'transform-inline-environment-variables',
{
include: ['NODE_ENV'],
},
],
'@babel/plugin-transform-runtime',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-object-rest-spread',
'lodash',
'@babel/plugin-proposal-class-properties',
],
env: {
esm: {
plugins: [patternflyTransformImports('esm'), fecTransformImports('esm')],
},
production: {
plugins: [patternflyTransformImports('esm'), fecTransformImports('esm')],
},
development: {
plugins: [patternflyTransformImports('esm'), fecTransformImports('esm')],
},
componentTest: {
plugins: ['istanbul'],
},
},
};