1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/packages/next/build/babel/plugins/next-to-next-server.ts

26 lines
834 B
TypeScript
Raw Normal View History

import {PluginObj} from '@babel/core'
import {NodePath} from '@babel/traverse'
import {ImportDeclaration} from '@babel/types'
2018-10-05 21:40:36 +00:00
// Rewrite imports using next/<something> to next-server/<something>
export default function NextToNextServer (): PluginObj {
2018-10-05 21:40:36 +00:00
return {
visitor: {
ImportDeclaration (path: NodePath<ImportDeclaration>) {
2018-10-05 21:40:36 +00:00
const source = path.node.source.value
if (source === 'next/dynamic') {
path.node.source.value = 'next-server/dynamic'
}
if (source === 'next/constants') {
path.node.source.value = 'next-server/constants'
}
2018-10-05 21:40:36 +00:00
if (source === 'next/config') {
path.node.source.value = 'next-server/config'
}
if (source === 'next/head') {
path.node.source.value = 'next-server/head'
}
}
}
}
}