UNPKG

bob-the-bundler

Version:
34 lines (33 loc) 1.23 kB
export function rewriteExports(exports, distDir) { const newExports = { ...exports }; for (const [key, value] of Object.entries(newExports)) { if (!value) continue; let newValue = value; if (typeof newValue === 'string') { newValue = newValue.replace(`${distDir}/`, ''); } else if (typeof newValue === 'object' && newValue != null) { function transformValue(value) { if (value == null) { return; } if (typeof value === 'object') { const newValue = {}; for (const [key, path] of Object.entries(value)) { newValue[key] = path.replace(`${distDir}/`, ''); } return newValue; } return value.replace(`${distDir}/`, ''); } newValue = { require: transformValue(newValue.require), import: transformValue(newValue.import), default: transformValue(newValue.import), }; } newExports[key.replace(`${distDir}/`, '')] = newValue; } return newExports; }