diff --git a/packages/next-server/package.json b/packages/next-server/package.json index 62dc836c..081f527e 100644 --- a/packages/next-server/package.json +++ b/packages/next-server/package.json @@ -24,10 +24,12 @@ ] }, "dependencies": { + "@babel/runtime-corejs2": "^7.1.2", "ansi-html": "0.0.7", "etag": "1.8.1", "find-up": "3.0.0", "fresh": "0.5.2", + "hoist-non-react-statics": "^3.0.1", "htmlescape": "1.1.1", "http-errors": "1.6.2", "path-to-regexp": "2.1.0", diff --git a/packages/next/app.js b/packages/next/app.js index 0bcca764..5437bb67 100644 --- a/packages/next/app.js +++ b/packages/next/app.js @@ -1 +1 @@ -module.exports = require('./dist/lib/app') +module.exports = require('./dist/pages/_app') diff --git a/packages/next/build/webpack.js b/packages/next/build/webpack.js index fb871e55..1881e942 100644 --- a/packages/next/build/webpack.js +++ b/packages/next/build/webpack.js @@ -32,14 +32,20 @@ function externalsConfig (dir, isServer) { return externals } + const notExternalModules = ['next/app', 'next/document', 'next/error'] + externals.push((context, request, callback) => { - resolve(request, { basedir: dir, preserveSymlinks: true }, (err, res) => { + if (notExternalModules.indexOf(request) !== -1) { + return callback() + } + + resolve(request, { basedir: context, preserveSymlinks: true }, (err, res) => { if (err) { return callback() } // Default pages have to be transpiled - if (res.match(/node_modules[/\\]next[/\\]dist[/\\]pages/)) { + if (res.match(/next[/\\]dist[/\\]pages/)) { return callback() } diff --git a/packages/next/document.js b/packages/next/document.js index 18bc2528..5741035f 100644 --- a/packages/next/document.js +++ b/packages/next/document.js @@ -1 +1 @@ -module.exports = require('./dist/server/document') +module.exports = require('./dist/pages/_document') diff --git a/packages/next/error.js b/packages/next/error.js index 1dd94bb4..899cd046 100644 --- a/packages/next/error.js +++ b/packages/next/error.js @@ -1 +1 @@ -module.exports = require('./dist/lib/error') +module.exports = require('./dist/pages/_error') diff --git a/packages/next/lib/app.js b/packages/next/lib/app.js deleted file mode 100644 index d0e558bd..00000000 --- a/packages/next/lib/app.js +++ /dev/null @@ -1,116 +0,0 @@ -import React, { Component } from 'react' -import PropTypes from 'prop-types' -import { execOnce, loadGetInitialProps } from 'next-server/dist/lib/utils' -import { makePublicRouterInstance } from 'next-server/router' - -export default class App extends Component { - static childContextTypes = { - headManager: PropTypes.object, - router: PropTypes.object - } - - static async getInitialProps ({ Component, router, ctx }) { - const pageProps = await loadGetInitialProps(Component, ctx) - return {pageProps} - } - - getChildContext () { - const { headManager } = this.props - return { - headManager, - router: makePublicRouterInstance(this.props.router) - } - } - - // Kept here for backwards compatibility. - // When someone ended App they could call `super.componentDidCatch`. This is now deprecated. - componentDidCatch (err) { - throw err - } - - render () { - const {router, Component, pageProps} = this.props - const url = createUrl(router) - return - - - } -} - -export class Container extends Component { - componentDidMount () { - this.scrollToHash() - } - - componentDidUpdate () { - this.scrollToHash() - } - - scrollToHash () { - let { hash } = window.location - hash = hash ? hash.substring(1) : false - if (!hash) return - - const el = document.getElementById(hash) - if (!el) return - - // If we call scrollIntoView() in here without a setTimeout - // it won't scroll properly. - setTimeout(() => el.scrollIntoView(), 0) - } - - render () { - return this.props.children - } -} - -const warnUrl = execOnce(() => { - if (process.env.NODE_ENV !== 'production') { - console.error(`Warning: the 'url' property is deprecated. https://err.sh/zeit/next.js/url-deprecated`) - } -}) - -export function createUrl (router) { - // This is to make sure we don't references the router object at call time - const {pathname, asPath, query} = router - return { - get query () { - warnUrl() - return query - }, - get pathname () { - warnUrl() - return pathname - }, - get asPath () { - warnUrl() - return asPath - }, - back: () => { - warnUrl() - router.back() - }, - push: (url, as) => { - warnUrl() - return router.push(url, as) - }, - pushTo: (href, as) => { - warnUrl() - const pushRoute = as ? href : null - const pushUrl = as || href - - return router.push(pushRoute, pushUrl) - }, - replace: (url, as) => { - warnUrl() - return router.replace(url, as) - }, - replaceTo: (href, as) => { - warnUrl() - const replaceRoute = as ? href : null - const replaceUrl = as || href - - return router.replace(replaceRoute, replaceUrl) - } - } -} diff --git a/packages/next/lib/error.js b/packages/next/lib/error.js deleted file mode 100644 index cef92cf7..00000000 --- a/packages/next/lib/error.js +++ /dev/null @@ -1,79 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import HTTPStatus from 'http-status' -import Head from 'next-server/head' - -export default class Error extends React.Component { - static getInitialProps ({ res, err }) { - const statusCode = res ? res.statusCode : (err ? err.statusCode : null) - return { statusCode } - } - - render () { - const { statusCode } = this.props - const title = statusCode === 404 - ? 'This page could not be found' - : HTTPStatus[statusCode] || 'An unexpected error has occurred' - - return
- - - {statusCode}: {title} - -
-