feat: webpack global override hook all
This commit is contained in:
parent
edde0d0d75
commit
8beb23ae69
1 changed files with 10 additions and 1 deletions
|
@ -51,11 +51,20 @@ export const webpackHook = (moduleId: string, moduleOverrides: { [id: string]: M
|
||||||
return t(moduleId)
|
return t(moduleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ALL = '*'
|
||||||
|
|
||||||
export const webpackGlobalOverride = (() => {
|
export const webpackGlobalOverride = (() => {
|
||||||
const moduleOverrides: { [id: string]: Module } = {}
|
const moduleOverrides: { [id: string]: Module } = {}
|
||||||
|
|
||||||
function applyOverride (pack: WebpackJson[0]) {
|
function applyOverride (pack: WebpackJson[0]) {
|
||||||
Object.entries(moduleOverrides).forEach(([id, override]) => {
|
let entries = Object.entries(moduleOverrides)
|
||||||
|
// apply to all
|
||||||
|
const all = moduleOverrides[ALL]
|
||||||
|
if (all) {
|
||||||
|
entries = Object.keys(pack[1]).map(id => [id, all])
|
||||||
|
}
|
||||||
|
|
||||||
|
entries.forEach(([id, override]) => {
|
||||||
const mod = pack[1][id]
|
const mod = pack[1][id]
|
||||||
if (mod) {
|
if (mod) {
|
||||||
pack[1][id] = function (n, r, t) {
|
pack[1][id] = function (n, r, t) {
|
||||||
|
|
Loading…
Reference in a new issue