mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Get config from one location (#3801)
* Remove obsolete clean.js * Remove unused root-module-relative-path * Single source of configuration * Fix next export
This commit is contained in:
parent
4469bd056c
commit
64379ee342
|
@ -1,8 +0,0 @@
|
||||||
import { resolve } from 'path'
|
|
||||||
import del from 'del'
|
|
||||||
import getConfig from '../config'
|
|
||||||
|
|
||||||
export default function clean (dir) {
|
|
||||||
const dist = getConfig(dir).distDir
|
|
||||||
return del(resolve(dir, dist), { force: true })
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Next.js needs to use module.resolve to generate paths to modules it includes,
|
|
||||||
// but those paths need to be relative to something so that they're portable
|
|
||||||
// across directories and machines.
|
|
||||||
//
|
|
||||||
// This function returns paths relative to the top-level 'node_modules'
|
|
||||||
// directory found in the path. If none is found, returns the complete path.
|
|
||||||
|
|
||||||
import { sep } from 'path'
|
|
||||||
|
|
||||||
const RELATIVE_START = `node_modules${sep}`
|
|
||||||
|
|
||||||
// Pass in the module's `require` object since it's module-specific.
|
|
||||||
export default (moduleRequire) => (path) => {
|
|
||||||
// package.json removed because babel-runtime is resolved as
|
|
||||||
// "babel-runtime/package"
|
|
||||||
const absolutePath = moduleRequire.resolve(path)
|
|
||||||
.replace(/[\\/]package\.json$/, '')
|
|
||||||
|
|
||||||
const relativeStartIndex = absolutePath.indexOf(RELATIVE_START)
|
|
||||||
|
|
||||||
if (relativeStartIndex === -1) {
|
|
||||||
return absolutePath
|
|
||||||
}
|
|
||||||
|
|
||||||
return absolutePath.substring(relativeStartIndex + RELATIVE_START.length)
|
|
||||||
}
|
|
|
@ -85,6 +85,7 @@ export default async function (dir, options, configuration) {
|
||||||
// Start the rendering process
|
// Start the rendering process
|
||||||
const renderOpts = {
|
const renderOpts = {
|
||||||
dir,
|
dir,
|
||||||
|
dist: config.distDir,
|
||||||
buildStats,
|
buildStats,
|
||||||
buildId,
|
buildId,
|
||||||
nextExport: true,
|
nextExport: true,
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import { join, relative, sep } from 'path'
|
import { join, relative, sep } from 'path'
|
||||||
import WebpackDevMiddleware from 'webpack-dev-middleware'
|
import WebpackDevMiddleware from 'webpack-dev-middleware'
|
||||||
import WebpackHotMiddleware from 'webpack-hot-middleware'
|
import WebpackHotMiddleware from 'webpack-hot-middleware'
|
||||||
|
import del from 'del'
|
||||||
import onDemandEntryHandler from './on-demand-entry-handler'
|
import onDemandEntryHandler from './on-demand-entry-handler'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import getBaseWebpackConfig from './build/webpack'
|
import getBaseWebpackConfig from './build/webpack'
|
||||||
import clean from './build/clean'
|
|
||||||
import getConfig from './config'
|
|
||||||
import UUID from 'uuid'
|
import UUID from 'uuid'
|
||||||
import {
|
import {
|
||||||
IS_BUNDLED_PAGE,
|
IS_BUNDLED_PAGE,
|
||||||
|
@ -13,7 +12,7 @@ import {
|
||||||
} from './utils'
|
} from './utils'
|
||||||
|
|
||||||
export default class HotReloader {
|
export default class HotReloader {
|
||||||
constructor (dir, { quiet, conf } = {}) {
|
constructor (dir, { quiet, config } = {}) {
|
||||||
this.dir = dir
|
this.dir = dir
|
||||||
this.quiet = quiet
|
this.quiet = quiet
|
||||||
this.middlewares = []
|
this.middlewares = []
|
||||||
|
@ -32,7 +31,7 @@ export default class HotReloader {
|
||||||
// it should be the same value.
|
// it should be the same value.
|
||||||
this.buildId = UUID.v4()
|
this.buildId = UUID.v4()
|
||||||
|
|
||||||
this.config = getConfig(dir, conf)
|
this.config = config
|
||||||
}
|
}
|
||||||
|
|
||||||
async run (req, res) {
|
async run (req, res) {
|
||||||
|
@ -55,8 +54,12 @@ export default class HotReloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async clean () {
|
||||||
|
return del(join(this.dir, this.config.distDir), { force: true })
|
||||||
|
}
|
||||||
|
|
||||||
async start () {
|
async start () {
|
||||||
await clean(this.dir)
|
await this.clean()
|
||||||
|
|
||||||
const configs = await Promise.all([
|
const configs = await Promise.all([
|
||||||
getBaseWebpackConfig(this.dir, { dev: true, isServer: false, config: this.config }),
|
getBaseWebpackConfig(this.dir, { dev: true, isServer: false, config: this.config }),
|
||||||
|
@ -86,7 +89,7 @@ export default class HotReloader {
|
||||||
async reload () {
|
async reload () {
|
||||||
this.stats = null
|
this.stats = null
|
||||||
|
|
||||||
await clean(this.dir)
|
await this.clean()
|
||||||
|
|
||||||
const configs = await Promise.all([
|
const configs = await Promise.all([
|
||||||
getBaseWebpackConfig(this.dir, { dev: true, isServer: false, config: this.config }),
|
getBaseWebpackConfig(this.dir, { dev: true, isServer: false, config: this.config }),
|
||||||
|
|
|
@ -32,11 +32,12 @@ export default class Server {
|
||||||
this.dev = dev
|
this.dev = dev
|
||||||
this.quiet = quiet
|
this.quiet = quiet
|
||||||
this.router = new Router()
|
this.router = new Router()
|
||||||
this.hotReloader = dev ? this.getHotReloader(this.dir, { quiet, conf }) : null
|
|
||||||
this.http = null
|
this.http = null
|
||||||
this.config = getConfig(this.dir, conf)
|
this.config = getConfig(this.dir, conf)
|
||||||
this.dist = this.config.distDir
|
this.dist = this.config.distDir
|
||||||
|
|
||||||
|
this.hotReloader = dev ? this.getHotReloader(this.dir, { quiet, config: this.config }) : null
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
updateNotifier(pkg, 'next')
|
updateNotifier(pkg, 'next')
|
||||||
}
|
}
|
||||||
|
@ -51,6 +52,7 @@ export default class Server {
|
||||||
dev,
|
dev,
|
||||||
staticMarkup,
|
staticMarkup,
|
||||||
dir: this.dir,
|
dir: this.dir,
|
||||||
|
dist: this.dist,
|
||||||
hotReloader: this.hotReloader,
|
hotReloader: this.hotReloader,
|
||||||
buildStats: this.buildStats,
|
buildStats: this.buildStats,
|
||||||
buildId: this.buildId,
|
buildId: this.buildId,
|
||||||
|
@ -183,8 +185,7 @@ export default class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dist = getConfig(this.dir).distDir
|
const path = join(this.dir, this.dist, 'bundles', 'pages', `${page}.js.map`)
|
||||||
const path = join(this.dir, dist, 'bundles', 'pages', `${page}.js.map`)
|
|
||||||
await serveStatic(req, res, path)
|
await serveStatic(req, res, path)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import send from 'send'
|
||||||
import generateETag from 'etag'
|
import generateETag from 'etag'
|
||||||
import fresh from 'fresh'
|
import fresh from 'fresh'
|
||||||
import requirePage from './require'
|
import requirePage from './require'
|
||||||
import getConfig from './config'
|
|
||||||
import { Router } from '../lib/router'
|
import { Router } from '../lib/router'
|
||||||
import { loadGetInitialProps, isResSent } from '../lib/utils'
|
import { loadGetInitialProps, isResSent } from '../lib/utils'
|
||||||
import { getAvailableChunks } from './utils'
|
import { getAvailableChunks } from './utils'
|
||||||
|
@ -41,6 +40,7 @@ async function doRender (req, res, pathname, query, {
|
||||||
hotReloader,
|
hotReloader,
|
||||||
assetPrefix,
|
assetPrefix,
|
||||||
availableChunks,
|
availableChunks,
|
||||||
|
dist,
|
||||||
dir = process.cwd(),
|
dir = process.cwd(),
|
||||||
dev = false,
|
dev = false,
|
||||||
staticMarkup = false,
|
staticMarkup = false,
|
||||||
|
@ -52,8 +52,6 @@ async function doRender (req, res, pathname, query, {
|
||||||
await ensurePage(page, { dir, hotReloader })
|
await ensurePage(page, { dir, hotReloader })
|
||||||
}
|
}
|
||||||
|
|
||||||
const dist = getConfig(dir).distDir
|
|
||||||
|
|
||||||
const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document')
|
const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document')
|
||||||
|
|
||||||
let Component = requirePage(page, {dir, dist})
|
let Component = requirePage(page, {dir, dist})
|
||||||
|
|
Loading…
Reference in a new issue