rsnext/packages/next/build/webpack/config/helpers.ts
Joe Haddad 9b6ea9d466 Refactor Webpack Configuration (#9651)
* WIP

* Move data experiment

* Do not throw away rules

* Remove test code

* Correct next data behavior

* Add support for async composing

* Remove unnecessary workaround

* Rename Field
2019-12-09 14:08:15 -06:00

42 lines
877 B
TypeScript

import curry from 'lodash.curry'
import { Configuration, 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(rule => rule.oneOf)
if (existing) {
existing.oneOf!.push(...rule.oneOf)
return config
}
}
config.module.rules.push(rule)
return config
})
export const unshiftLoader = curry(function loader(
rule: RuleSetRule,
config: Configuration
) {
if (!config.module) {
config.module = { rules: [] }
}
if (rule.oneOf) {
const existing = config.module.rules.find(rule => rule.oneOf)
if (existing) {
existing.oneOf!.unshift(...rule.oneOf)
return config
}
}
config.module.rules.unshift(rule)
return config
})