1
0
Fork 0
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:
Tim Neutkens 2018-02-14 16:17:41 +01:00 committed by Arunoda Susiripala
parent 4469bd056c
commit 64379ee342
6 changed files with 15 additions and 46 deletions

View file

@ -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 })
}

View file

@ -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)
}

View file

@ -85,6 +85,7 @@ export default async function (dir, options, configuration) {
// Start the rendering process
const renderOpts = {
dir,
dist: config.distDir,
buildStats,
buildId,
nextExport: true,

View file

@ -1,11 +1,10 @@
import { join, relative, sep } from 'path'
import WebpackDevMiddleware from 'webpack-dev-middleware'
import WebpackHotMiddleware from 'webpack-hot-middleware'
import del from 'del'
import onDemandEntryHandler from './on-demand-entry-handler'
import webpack from 'webpack'
import getBaseWebpackConfig from './build/webpack'
import clean from './build/clean'
import getConfig from './config'
import UUID from 'uuid'
import {
IS_BUNDLED_PAGE,
@ -13,7 +12,7 @@ import {
} from './utils'
export default class HotReloader {
constructor (dir, { quiet, conf } = {}) {
constructor (dir, { quiet, config } = {}) {
this.dir = dir
this.quiet = quiet
this.middlewares = []
@ -32,7 +31,7 @@ export default class HotReloader {
// it should be the same value.
this.buildId = UUID.v4()
this.config = getConfig(dir, conf)
this.config = config
}
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 () {
await clean(this.dir)
await this.clean()
const configs = await Promise.all([
getBaseWebpackConfig(this.dir, { dev: true, isServer: false, config: this.config }),
@ -86,7 +89,7 @@ export default class HotReloader {
async reload () {
this.stats = null
await clean(this.dir)
await this.clean()
const configs = await Promise.all([
getBaseWebpackConfig(this.dir, { dev: true, isServer: false, config: this.config }),

View file

@ -32,11 +32,12 @@ export default class Server {
this.dev = dev
this.quiet = quiet
this.router = new Router()
this.hotReloader = dev ? this.getHotReloader(this.dir, { quiet, conf }) : null
this.http = null
this.config = getConfig(this.dir, conf)
this.dist = this.config.distDir
this.hotReloader = dev ? this.getHotReloader(this.dir, { quiet, config: this.config }) : null
if (dev) {
updateNotifier(pkg, 'next')
}
@ -51,6 +52,7 @@ export default class Server {
dev,
staticMarkup,
dir: this.dir,
dist: this.dist,
hotReloader: this.hotReloader,
buildStats: this.buildStats,
buildId: this.buildId,
@ -183,8 +185,7 @@ export default class Server {
}
}
const dist = getConfig(this.dir).distDir
const path = join(this.dir, dist, 'bundles', 'pages', `${page}.js.map`)
const path = join(this.dir, this.dist, 'bundles', 'pages', `${page}.js.map`)
await serveStatic(req, res, path)
},

View file

@ -5,7 +5,6 @@ import send from 'send'
import generateETag from 'etag'
import fresh from 'fresh'
import requirePage from './require'
import getConfig from './config'
import { Router } from '../lib/router'
import { loadGetInitialProps, isResSent } from '../lib/utils'
import { getAvailableChunks } from './utils'
@ -41,6 +40,7 @@ async function doRender (req, res, pathname, query, {
hotReloader,
assetPrefix,
availableChunks,
dist,
dir = process.cwd(),
dev = false,
staticMarkup = false,
@ -52,8 +52,6 @@ async function doRender (req, res, pathname, query, {
await ensurePage(page, { dir, hotReloader })
}
const dist = getConfig(dir).distDir
const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document')
let Component = requirePage(page, {dir, dist})