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
Tim Neutkens a9cf735f50
Convert babel plugins to typescript (#5789)
Slowly moving files over 💯
2018-12-02 18:30:00 +01:00

29 lines
938 B
TypeScript

import {PluginObj} from '@babel/core'
import {NodePath} from '@babel/traverse'
import {ImportDeclaration} from '@babel/types'
// Rewrite imports using next/<something> to next-server/<something>
export default function NextToNextServer (): PluginObj {
return {
visitor: {
ImportDeclaration (path: NodePath<ImportDeclaration>) {
const source = path.node.source.value
if (source === 'next/asset') {
path.node.source.value = 'next-server/asset'
}
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'
}
}
}
}
}