-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(next): Fix breaking changes in 14.1
- Loading branch information
Showing
1 changed file
with
5 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,12 @@ | ||
const isNext12 = (config) => !!config.module.rules.find((rule) => rule.oneOf); | ||
|
||
const updateNextGreaterThan12Config = (config) => { | ||
const oneOfRule = config.module.rules.find((rule) => rule.oneOf); | ||
|
||
// Next 12 has multiple TS loaders, and we need to update all of them. | ||
const tsRules = oneOfRule.oneOf.filter( | ||
(rule) => rule.test && rule.test.toString().includes("tsx|ts") | ||
); | ||
|
||
tsRules.forEach((rule) => { | ||
// eslint-disable-next-line no-param-reassign | ||
rule.include = undefined; | ||
}); | ||
|
||
return config; | ||
}; | ||
|
||
const updateNextLessThan12Config = (config) => { | ||
// Next < 12 uses a single Babel loader. | ||
const tsRule = config.module.rules.find( | ||
(rule) => rule.test && rule.test.toString().includes("tsx|ts") | ||
); | ||
|
||
tsRule.include = undefined; | ||
tsRule.exclude = /node_modules/; | ||
|
||
return config; | ||
}; | ||
|
||
module.exports = { | ||
/** | ||
* You can use the following experimental flag if you're on Next >= 10.1.0. | ||
* Note that this can change/break without warning. | ||
* This will become the default eventually. | ||
* | ||
* @see https://github.com/vercel/next.js/discussions/26420#discussioncomment-6568785 | ||
* @see https://github.com/vercel/next.js/pull/22867 | ||
*/ | ||
// experimental: { | ||
// externalDir: true, | ||
// }, | ||
webpack: (config) => { | ||
if (isNext12(config)) { | ||
return updateNextGreaterThan12Config(config); | ||
} | ||
|
||
return updateNextLessThan12Config(config); | ||
experimental: { | ||
externalDir: true, | ||
}, | ||
}; |