mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Rename dist
to server
to be more consistent (#4506)
Previously we called this directory holding the pages/chunks for server rendering `.next/dist` instead of `.next/server` which is confusing both when looking at it and in the codebase, since there's also `distDir` as a configuration option. Also made this a constant in `next/constants` so functionality using this can be easily found.
This commit is contained in:
parent
14a7264c27
commit
098f3fd7e9
|
@ -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'
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
|
@ -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}),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = {
|
||||
test: 'error'
|
||||
}
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = {
|
||||
test: 'hello'
|
||||
}
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = {
|
||||
test: 'world'
|
||||
}
|
||||
}
|
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in a new issue