UNPKG

871 BJavaScriptView Raw
1'use strict'
2
3/**
4 * 文件说明:
5 * ----------------------------------------
6 * 创建用户: leo
7 * 创建日期 2019/1/3
8 */
9
10const {cloneDeep, merge} = require('lodash')
11
12function stripDotSlashPrefix(path) {
13 return path.replace(/^\.\//, '')
14}
15
16module.exports = function(entry, opts) {
17 let clone = cloneDeep(opts)
18 const stripedEntry = stripDotSlashPrefix(entry)
19 if (clone.overridesByEntry) {
20 Object.keys(clone.overridesByEntry).forEach((key) => {
21 const stripedKey = stripDotSlashPrefix(key)
22 if (stripedKey !== key) {
23 clone.overridesByEntry[stripedKey] = clone.overridesByEntry[key]
24 }
25 })
26 if (clone.overridesByEntry[stripedEntry]) {
27 clone = merge(clone, clone.overridesByEntry[stripedEntry])
28 }
29 delete clone.overridesByEntry
30 }
31 return clone
32}