rsnext/packages/next/build/babel/plugins/next-to-next-server.ts

23 lines
722 B
TypeScript
Raw Normal View History

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