|
| 1 | +require.extensions['.css'] = () => undefined; |
| 2 | +const path = require('path'); |
| 3 | +const glob = require('glob'); |
| 4 | + |
| 5 | +const mapper = { |
| 6 | + TextVariants: 'Text', |
| 7 | + ButtonVariant: 'Button', |
| 8 | + DropdownPosition: 'dropdownConstants', |
| 9 | + TextListVariants: 'TextList', |
| 10 | + TextListItemVariants: 'TextListItem' |
| 11 | +}; |
| 12 | + |
| 13 | +const camelToSnake = (string) => { |
| 14 | + return string |
| 15 | + .replace(/[\w]([A-Z])/g, function(m) { |
| 16 | + return m[0] + '-' + m[1]; |
| 17 | + }) |
| 18 | + .toLowerCase(); |
| 19 | +}; |
| 20 | + |
1 | 21 | module.exports = { |
2 | 22 | extends: '../../babel.config.js', |
| 23 | + env: { |
| 24 | + cjs: { |
| 25 | + plugins: [ |
| 26 | + [ |
| 27 | + 'transform-imports', |
| 28 | + { |
| 29 | + '@data-driven-forms/react-form-renderer': { |
| 30 | + transform: (importName) => `@data-driven-forms/react-form-renderer/dist/cjs/${camelToSnake(importName)}`, |
| 31 | + preventFullImport: true |
| 32 | + } |
| 33 | + }, |
| 34 | + '@data-driven-forms/react-form-renderer-CJS' |
| 35 | + ], |
| 36 | + [ |
| 37 | + 'transform-imports', |
| 38 | + { |
| 39 | + '@patternfly/react-core': { |
| 40 | + transform: (importName) => { |
| 41 | + let res; |
| 42 | + const files = glob.sync( |
| 43 | + path.resolve(__dirname, `../../node_modules/@patternfly/react-core/dist/js/**/${mapper[importName] || importName}.js`) |
| 44 | + ); |
| 45 | + if (files.length > 0) { |
| 46 | + res = files[0]; |
| 47 | + } else { |
| 48 | + throw new Error(`File with importName ${importName} does not exist`); |
| 49 | + } |
| 50 | + |
| 51 | + res = res.replace(path.resolve(__dirname, '../../node_modules/'), ''); |
| 52 | + res = res.replace(/^\//, ''); |
| 53 | + return res; |
| 54 | + }, |
| 55 | + preventFullImport: false, |
| 56 | + skipDefaultConversion: true |
| 57 | + } |
| 58 | + }, |
| 59 | + 'react-core-CJS' |
| 60 | + ], |
| 61 | + |
| 62 | + [ |
| 63 | + 'transform-imports', |
| 64 | + { |
| 65 | + '@patternfly/react-icons': { |
| 66 | + transform: (importName) => |
| 67 | + `@patternfly/react-icons/dist/js/icons/${importName |
| 68 | + .split(/(?=[A-Z])/) |
| 69 | + .join('-') |
| 70 | + .toLowerCase()}`, |
| 71 | + preventFullImport: true |
| 72 | + } |
| 73 | + }, |
| 74 | + 'react-icons-CJS' |
| 75 | + ] |
| 76 | + ] |
| 77 | + }, |
| 78 | + esm: { |
| 79 | + plugins: [ |
| 80 | + [ |
| 81 | + 'transform-imports', |
| 82 | + { |
| 83 | + '@data-driven-forms/react-form-renderer': { |
| 84 | + transform: (importName) => `@data-driven-forms/react-form-renderer/dist/esm/${camelToSnake(importName)}`, |
| 85 | + preventFullImport: true |
| 86 | + } |
| 87 | + }, |
| 88 | + '@data-driven-forms/react-form-renderer-ESM' |
| 89 | + ], |
| 90 | + [ |
| 91 | + 'transform-imports', |
| 92 | + { |
| 93 | + '@patternfly/react-core': { |
| 94 | + transform: (importName) => { |
| 95 | + let res; |
| 96 | + const files = glob.sync( |
| 97 | + path.resolve(__dirname, `../../node_modules/@patternfly/react-core/dist/esm/**/${mapper[importName] || importName}.js`) |
| 98 | + ); |
| 99 | + if (files.length > 0) { |
| 100 | + res = files[0]; |
| 101 | + } else { |
| 102 | + throw new Error(`File with importName ${importName} does not exist`); |
| 103 | + } |
| 104 | + |
| 105 | + res = res.replace(path.resolve(__dirname, '../../node_modules/'), ''); |
| 106 | + res = res.replace(/^\//, ''); |
| 107 | + return res; |
| 108 | + }, |
| 109 | + preventFullImport: false, |
| 110 | + skipDefaultConversion: true |
| 111 | + } |
| 112 | + }, |
| 113 | + 'react-core-ESM' |
| 114 | + ], |
| 115 | + |
| 116 | + [ |
| 117 | + 'transform-imports', |
| 118 | + { |
| 119 | + '@patternfly/react-icons': { |
| 120 | + transform: (importName) => |
| 121 | + `@patternfly/react-icons/dist/esm/icons/${importName |
| 122 | + .split(/(?=[A-Z])/) |
| 123 | + .join('-') |
| 124 | + .toLowerCase()}`, |
| 125 | + preventFullImport: true |
| 126 | + } |
| 127 | + }, |
| 128 | + 'react-icons-ESM' |
| 129 | + ] |
| 130 | + ] |
| 131 | + } |
| 132 | + } |
3 | 133 | }; |
0 commit comments