Skip to content

Commit

Permalink
Correct next data behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Dec 6, 2019
1 parent 96ee42d commit 4df7bd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/next/build/webpack/config/blocks/experiment-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import curry from 'lodash.curry'
import path from 'path'
import { Configuration } from 'webpack'
import { loader } from '../helpers'
import { unshiftLoader } from '../helpers'
import { ConfigurationContext, pipe } from '../utils'

export const experimentData = curry(function experimentData(
Expand All @@ -18,7 +18,7 @@ export const experimentData = curry(function experimentData(
}

const fn = pipe(
loader({
unshiftLoader({
test: /\.(tsx|ts|js|mjs|jsx)$/,
include: [path.join(ctx.rootDirectory, 'data')],
use: 'next-data-loader',
Expand Down
20 changes: 20 additions & 0 deletions packages/next/build/webpack/config/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ export const loader = curry(function loader(
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
})

0 comments on commit 4df7bd3

Please sign in to comment.