b124ed2e14
Was going through _document and noticed some variable shadowing going on. Added a rule for it to our eslint configuration and went through all warnings with @Timer.
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import curry from 'next/dist/compiled/lodash.curry'
|
|
import { Configuration, Plugin, RuleSetRule } from 'webpack'
|
|
|
|
export const loader = curry(function loader(
|
|
rule: RuleSetRule,
|
|
config: Configuration
|
|
) {
|
|
if (!config.module) {
|
|
config.module = { rules: [] }
|
|
}
|
|
|
|
if (rule.oneOf) {
|
|
const existing = config.module.rules.find((arrayRule) => arrayRule.oneOf)
|
|
if (existing) {
|
|
existing.oneOf!.push(...rule.oneOf)
|
|
return config
|
|
}
|
|
}
|
|
|
|
config.module.rules.push(rule)
|
|
return config
|
|
})
|
|
|
|
export const unshiftLoader = curry(function unshiftLoader(
|
|
rule: RuleSetRule,
|
|
config: Configuration
|
|
) {
|
|
if (!config.module) {
|
|
config.module = { rules: [] }
|
|
}
|
|
|
|
if (rule.oneOf) {
|
|
const existing = config.module.rules.find((arrayRule) => arrayRule.oneOf)
|
|
if (existing) {
|
|
existing.oneOf!.unshift(...rule.oneOf)
|
|
return config
|
|
}
|
|
}
|
|
|
|
config.module.rules.unshift(rule)
|
|
return config
|
|
})
|
|
|
|
export const plugin = curry(function plugin(p: Plugin, config: Configuration) {
|
|
if (!config.plugins) {
|
|
config.plugins = []
|
|
}
|
|
config.plugins.push(p)
|
|
return config
|
|
})
|