6fd2a7fa31
These types are no longer needed as we are only leveraging webpack 5 so this finishes migrating our types away from webpack 4's types.
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import curry from 'next/dist/compiled/lodash.curry'
|
|
import { webpack } from 'next/dist/compiled/webpack/webpack'
|
|
|
|
export const loader = curry(function loader(
|
|
rule: webpack.RuleSetRule,
|
|
config: webpack.Configuration
|
|
) {
|
|
if (!config.module) {
|
|
config.module = { rules: [] }
|
|
}
|
|
|
|
if (rule.oneOf) {
|
|
const existing = config.module.rules?.find(
|
|
(arrayRule) =>
|
|
arrayRule && typeof arrayRule === 'object' && arrayRule.oneOf
|
|
)
|
|
if (existing && typeof existing === 'object') {
|
|
existing.oneOf!.push(...rule.oneOf)
|
|
return config
|
|
}
|
|
}
|
|
|
|
config.module.rules?.push(rule)
|
|
return config
|
|
})
|
|
|
|
export const unshiftLoader = curry(function unshiftLoader(
|
|
rule: webpack.RuleSetRule,
|
|
config: webpack.Configuration
|
|
) {
|
|
if (!config.module) {
|
|
config.module = { rules: [] }
|
|
}
|
|
|
|
if (rule.oneOf) {
|
|
const existing = config.module.rules?.find(
|
|
(arrayRule) =>
|
|
arrayRule && typeof arrayRule === 'object' && arrayRule.oneOf
|
|
)
|
|
if (existing && typeof existing === 'object') {
|
|
existing.oneOf?.unshift(...rule.oneOf)
|
|
return config
|
|
}
|
|
}
|
|
|
|
config.module.rules?.unshift(rule)
|
|
return config
|
|
})
|
|
|
|
export const plugin = curry(function plugin(
|
|
p: webpack.WebpackPluginInstance,
|
|
config: webpack.Configuration
|
|
) {
|
|
if (!config.plugins) {
|
|
config.plugins = []
|
|
}
|
|
config.plugins.push(p)
|
|
return config
|
|
})
|