rsnext/packages/next/build/webpack/config/helpers.ts
Tim Neutkens b124ed2e14
Added no-shadow rule to eslint (#13645)
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.
2020-06-01 21:00:22 +00:00

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
})