tachybase_todo/packages/father-build/src/normalizeBundleOpts.ts

25 lines
762 B
TypeScript
Raw Normal View History

2020-10-24 15:34:43 +08:00
import { cloneDeep, merge } from 'lodash';
import { IBundleOptions } from './types';
function stripDotSlashPrefix(path) {
return path.replace(/^\.\//, '');
}
export default function(entry: string, opts: IBundleOptions): IBundleOptions {
let clone = cloneDeep(opts);
const stripedEntry = stripDotSlashPrefix(entry);
if (clone.overridesByEntry) {
Object.keys(clone.overridesByEntry).forEach(key => {
const stripedKey = stripDotSlashPrefix(key);
if (stripedKey !== key) {
clone.overridesByEntry[stripedKey] = clone.overridesByEntry[key];
}
});
if (clone.overridesByEntry[stripedEntry]) {
clone = merge(clone, clone.overridesByEntry[stripedEntry]);
}
delete clone.overridesByEntry;
}
return clone;
}