From 0f6cff88bc9e587e9a0b14262066cb0f59dc32d0 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 5 Oct 2018 23:40:36 +0200 Subject: [PATCH] Add next-to-next-server --- .../babel/plugins/next-to-next-server.js | 31 +++++++++++++++++++ packages/next/build/babel/preset.js | 1 + packages/next/build/webpack.js | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 packages/next/build/babel/plugins/next-to-next-server.js diff --git a/packages/next/build/babel/plugins/next-to-next-server.js b/packages/next/build/babel/plugins/next-to-next-server.js new file mode 100644 index 00000000..22adf86a --- /dev/null +++ b/packages/next/build/babel/plugins/next-to-next-server.js @@ -0,0 +1,31 @@ +// Rewrite imports using next/ to next-server/ +export default function ({ types: t, template }) { + return { + visitor: { + ImportDeclaration (path) { + 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' + } + if (source === 'next/link') { + path.node.source.value = 'next-server/link' + } + if (source === 'next/router') { + path.node.source.value = 'next-server/router' + } + } + } + } +} diff --git a/packages/next/build/babel/preset.js b/packages/next/build/babel/preset.js index 3b79ab88..c6c907d2 100644 --- a/packages/next/build/babel/preset.js +++ b/packages/next/build/babel/preset.js @@ -47,6 +47,7 @@ module.exports = (context, opts = {}) => ({ require('babel-plugin-react-require'), require('@babel/plugin-syntax-dynamic-import'), require('./plugins/react-loadable-plugin'), + require('./plugins/next-to-next-server'), [require('@babel/plugin-proposal-class-properties'), opts['class-properties'] || {}], require('@babel/plugin-proposal-object-rest-spread'), [require('@babel/plugin-transform-runtime'), { diff --git a/packages/next/build/webpack.js b/packages/next/build/webpack.js index 1881e942..4dc8489e 100644 --- a/packages/next/build/webpack.js +++ b/packages/next/build/webpack.js @@ -32,7 +32,7 @@ function externalsConfig (dir, isServer) { return externals } - const notExternalModules = ['next/app', 'next/document', 'next/error'] + const notExternalModules = ['next/app', 'next/document', 'next/error', 'http-status'] externals.push((context, request, callback) => { if (notExternalModules.indexOf(request) !== -1) {