Commit 256970ac authored by JJ Kasper's avatar JJ Kasper Committed by Tim Neutkens

Remove next-to-next-server babel plugin (#6458)

After discussion it was decided instead of rewriting `next/config` and `next/head` imports to `next-server/config` and `next-server/head` we should just allow importing them as `next/config` and `next/head`
 
Fixes: #6187
parent fdb10d4f
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/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'
}
}
}
}
}
...@@ -68,7 +68,6 @@ module.exports = (context: any, options: NextBabelPresetOptions = {}): BabelPres ...@@ -68,7 +68,6 @@ module.exports = (context: any, options: NextBabelPresetOptions = {}): BabelPres
require('babel-plugin-react-require'), require('babel-plugin-react-require'),
require('@babel/plugin-syntax-dynamic-import'), require('@babel/plugin-syntax-dynamic-import'),
require('./plugins/react-loadable-plugin'), require('./plugins/react-loadable-plugin'),
require('./plugins/next-to-next-server'),
[require('@babel/plugin-proposal-class-properties'), options['class-properties'] || {}], [require('@babel/plugin-proposal-class-properties'), options['class-properties'] || {}],
require('@babel/plugin-proposal-object-rest-spread'), require('@babel/plugin-proposal-object-rest-spread'),
[require('@babel/plugin-transform-runtime'), { [require('@babel/plugin-transform-runtime'), {
......
...@@ -83,7 +83,11 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe ...@@ -83,7 +83,11 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
target: isServer ? 'node' : 'web', target: isServer ? 'node' : 'web',
externals: isServer && target !== 'serverless' ? [ externals: isServer && target !== 'serverless' ? [
(context, request, callback) => { (context, request, callback) => {
const notExternalModules = ['next/app', 'next/document', 'next/link', 'next/router', 'next/error', 'string-hash', 'hoist-non-react-statics', 'htmlescape'] const notExternalModules = [
'next/app', 'next/document', 'next/link', 'next/router', 'next/error',
'string-hash', 'hoist-non-react-statics', 'htmlescape','next/dynamic',
'next/constants', 'next/config', 'next/head'
]
if (notExternalModules.indexOf(request) !== -1) { if (notExternalModules.indexOf(request) !== -1) {
return callback() return callback()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment