chore: Add Babel plugin to disable Next.js link prefetching
This commit is contained in:
4
.babelrc
Normal file
4
.babelrc
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"presets": ["next/babel"],
|
||||
"plugins": ["./babel/disable-nextjs-link-prefetching"]
|
||||
}
|
||||
26
babel/disable-nextjs-link-prefetching.js
Normal file
26
babel/disable-nextjs-link-prefetching.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Based on the docs at https://nextjs.org/docs/api-reference/next/link, the
|
||||
* only way to disable prefetching is to make sure every <Link /> has <Link
|
||||
* prefetch={false} />
|
||||
*
|
||||
* We don't want to create a wrapper Component or go around changing every
|
||||
* single <Link />, so we use this Babel Plugin to add them in at build-time.
|
||||
*/
|
||||
module.exports = function (babel) {
|
||||
const { types: t } = babel
|
||||
return {
|
||||
name: 'disable-link-prefetching',
|
||||
visitor: {
|
||||
JSXOpeningElement(path) {
|
||||
if (path.node.name.name === 'Link') {
|
||||
path.node.attributes.push(
|
||||
t.jSXAttribute(
|
||||
t.jSXIdentifier('prefetch'),
|
||||
t.stringLiteral("force-off"),
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
7584
package-lock.json
generated
7584
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user