2018-12-02 17:30:00 +00:00
|
|
|
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>
|
2018-12-02 17:30:00 +00:00
|
|
|
export default function NextToNextServer (): PluginObj {
|
2018-10-05 21:40:36 +00:00
|
|
|
return {
|
|
|
|
visitor: {
|
2018-12-02 17:30:00 +00:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
if (source === 'next/config') {
|
|
|
|
path.node.source.value = 'next-server/config'
|
|
|
|
}
|
|
|
|
if (source === 'next/head') {
|
|
|
|
path.node.source.value = 'next-server/head'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|