diff --git a/lib/constants.js b/lib/constants.js index 19cb799242e5e64917eea5d6c207be4a93ad79ba..cbf93723c9dff26b8a4264c36cc4a1875ed08c9e 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -4,3 +4,4 @@ export const PHASE_PRODUCTION_SERVER = 'phase-production-server' export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server' export const PAGES_MANIFEST = 'pages-manifest.json' export const BUILD_MANIFEST = 'build-manifest.json' +export const SERVER_DIRECTORY = 'server' diff --git a/server/build/webpack.js b/server/build/webpack.js index e85e0dfff44550166e90ee2cb7ba613bb81c3663..accb5d9ca60832fd1dee8fb3bb4583d48e423ecd 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -12,18 +12,11 @@ import DynamicChunksPlugin from './plugins/dynamic-chunks-plugin' import UnlinkFilePlugin from './plugins/unlink-file-plugin' import PagesManifestPlugin from './plugins/pages-manifest-plugin' import BuildManifestPlugin from './plugins/build-manifest-plugin' +import {SERVER_DIRECTORY} from '../../lib/constants' const nextDir = path.join(__dirname, '..', '..', '..') const nextNodeModulesDir = path.join(nextDir, 'node_modules') const nextPagesDir = path.join(nextDir, 'pages') -const defaultPages = [ - '_error.js', - '_document.js', - '_app.js' -] -const interpolateNames = new Map(defaultPages.map((p) => { - return [path.join(nextPagesDir, p), `dist/bundles/pages/${p}`] -})) function externalsConfig (dir, isServer) { const externals = [] @@ -98,7 +91,7 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer } }, output: { - path: path.join(dir, config.distDir, isServer ? 'dist' : ''), // server compilation goes to `.next/dist` + path: path.join(dir, config.distDir, isServer ? SERVER_DIRECTORY : ''), filename: '[name]', libraryTarget: 'commonjs2', // This saves chunks with the name given via require.ensure() @@ -163,14 +156,6 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer dev && !isServer && new webpack.HotModuleReplacementPlugin(), // Hot module replacement dev && new UnlinkFilePlugin(), dev && new CaseSensitivePathPlugin(), // Since on macOS the filesystem is case-insensitive this will make sure your path are case-sensitive - dev && new webpack.LoaderOptionsPlugin({ - options: { - context: dir, - customInterpolateName (url, name, opts) { - return interpolateNames.get(this.resourcePath) || url - } - } - }), dev && new WriteFilePlugin({ exitOnErrors: false, log: false, diff --git a/server/export.js b/server/export.js index b3fb12614c9cb92ffa7a59b51a1cbd4441f1c079..8334a6e7efa5a7e66d5b6090c22cae1d89c66508 100644 --- a/server/export.js +++ b/server/export.js @@ -5,7 +5,7 @@ import walk from 'walk' import { extname, resolve, join, dirname, sep } from 'path' import { existsSync, readFileSync, writeFileSync } from 'fs' import getConfig from './config' -import {PHASE_EXPORT, PAGES_MANIFEST} from '../lib/constants' +import {PHASE_EXPORT, SERVER_DIRECTORY, PAGES_MANIFEST} from '../lib/constants' import { renderToHTML } from './render' import { getAvailableChunks } from './utils' import { setAssetPrefix } from '../lib/asset' @@ -23,7 +23,7 @@ export default async function (dir, options, configuration) { } const buildId = readFileSync(join(nextDir, 'BUILD_ID'), 'utf8') - const pagesManifest = require(join(nextDir, 'dist', PAGES_MANIFEST)) + const pagesManifest = require(join(nextDir, SERVER_DIRECTORY, PAGES_MANIFEST)) const pages = Object.keys(pagesManifest) const defaultPathMap = {} diff --git a/server/render.js b/server/render.js index 4dd5a836b9ca2015c5500c88d78379f4296a2a6d..3b0ef23dd13229e1a8420d115b285e38ca88fb6f 100644 --- a/server/render.js +++ b/server/render.js @@ -11,7 +11,7 @@ import { getAvailableChunks } from './utils' import Head, { defaultHead } from '../lib/head' import ErrorDebug from '../lib/error-debug' import { flushChunks } from '../lib/dynamic' -import { BUILD_MANIFEST } from '../lib/constants' +import { BUILD_MANIFEST, SERVER_DIRECTORY } from '../lib/constants' import { applySourcemaps } from './lib/source-map-support' const logger = console @@ -56,8 +56,8 @@ async function doRender (req, res, pathname, query, { await ensurePage(page, { dir, hotReloader }) } - const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document') - const appPath = join(dir, dist, 'dist', 'bundles', 'pages', '_app') + const documentPath = join(dir, dist, SERVER_DIRECTORY, 'bundles', 'pages', '_document') + const appPath = join(dir, dist, SERVER_DIRECTORY, 'bundles', 'pages', '_app') const buildManifest = require(join(dir, dist, BUILD_MANIFEST)) let [Component, Document, App] = await Promise.all([ requirePage(page, {dir, dist}), diff --git a/server/require.js b/server/require.js index dda23bc27381816943373daf2cc9146ba8eaacd6..816fe2bebbda2c2870a710685940d89a958b920c 100644 --- a/server/require.js +++ b/server/require.js @@ -1,5 +1,5 @@ import {join, posix} from 'path' -import {PAGES_MANIFEST} from '../lib/constants' +import {PAGES_MANIFEST, SERVER_DIRECTORY} from '../lib/constants' export function pageNotFoundError (page) { const err = new Error(`Cannot find module for page: ${page}`) @@ -28,7 +28,7 @@ export function normalizePagePath (page) { } export function getPagePath (page, {dir, dist}) { - const serverBuildPath = join(dir, dist, 'dist') + const serverBuildPath = join(dir, dist, SERVER_DIRECTORY) const pagesManifest = require(join(serverBuildPath, PAGES_MANIFEST)) try { diff --git a/test/isolated/_resolvedata/dist/bundles/pages/_error.js b/test/isolated/_resolvedata/server/bundles/pages/_error.js similarity index 94% rename from test/isolated/_resolvedata/dist/bundles/pages/_error.js rename to test/isolated/_resolvedata/server/bundles/pages/_error.js index 0af8646cffcd53d2b8e2f5cee96572ff3d85ddf4..3d2eea3bb6253d1047982fcdd6db61e7ecb33273 100644 --- a/test/isolated/_resolvedata/dist/bundles/pages/_error.js +++ b/test/isolated/_resolvedata/server/bundles/pages/_error.js @@ -1,3 +1,3 @@ module.exports = { test: 'error' -} \ No newline at end of file +} diff --git a/test/isolated/_resolvedata/dist/bundles/pages/index.js b/test/isolated/_resolvedata/server/bundles/pages/index.js similarity index 94% rename from test/isolated/_resolvedata/dist/bundles/pages/index.js rename to test/isolated/_resolvedata/server/bundles/pages/index.js index 30de59be17350d80d92ed8ac779b56be501b6dae..3dc6289b87274d0de00b4d890e30983238a9c465 100644 --- a/test/isolated/_resolvedata/dist/bundles/pages/index.js +++ b/test/isolated/_resolvedata/server/bundles/pages/index.js @@ -1,3 +1,3 @@ module.exports = { test: 'hello' -} \ No newline at end of file +} diff --git a/test/isolated/_resolvedata/dist/bundles/pages/non-existent-child.js b/test/isolated/_resolvedata/server/bundles/pages/non-existent-child.js similarity index 100% rename from test/isolated/_resolvedata/dist/bundles/pages/non-existent-child.js rename to test/isolated/_resolvedata/server/bundles/pages/non-existent-child.js diff --git a/test/isolated/_resolvedata/dist/bundles/pages/world.js b/test/isolated/_resolvedata/server/bundles/pages/world.js similarity index 94% rename from test/isolated/_resolvedata/dist/bundles/pages/world.js rename to test/isolated/_resolvedata/server/bundles/pages/world.js index 24ca31a39d6ac11af4f806c16f57f738e93ece9d..8e914ecb8d8997a36a391e7e0360f4606b47920e 100644 --- a/test/isolated/_resolvedata/dist/bundles/pages/world.js +++ b/test/isolated/_resolvedata/server/bundles/pages/world.js @@ -1,3 +1,3 @@ module.exports = { test: 'world' -} \ No newline at end of file +} diff --git a/test/isolated/_resolvedata/dist/pages-manifest.json b/test/isolated/_resolvedata/server/pages-manifest.json similarity index 100% rename from test/isolated/_resolvedata/dist/pages-manifest.json rename to test/isolated/_resolvedata/server/pages-manifest.json diff --git a/test/isolated/require-page.test.js b/test/isolated/require-page.test.js index bdd368de9f91f40dac060acff9f5dbe00c0de9c2..de7c63aba256e3caf01c88f0579bc4dad4dabfd9 100644 --- a/test/isolated/require-page.test.js +++ b/test/isolated/require-page.test.js @@ -1,10 +1,11 @@ /* global describe, it, expect */ import { join } from 'path' +import {SERVER_DIRECTORY} from 'next/constants' import requirePage, {getPagePath, normalizePagePath, pageNotFoundError} from '../../dist/server/require' const sep = '/' -const pathToBundles = join(__dirname, '_resolvedata', 'dist', 'bundles', 'pages') +const pathToBundles = join(__dirname, '_resolvedata', SERVER_DIRECTORY, 'bundles', 'pages') describe('pageNotFoundError', () => { it('Should throw error with ENOENT code', () => {