diff --git a/server/build/clean.js b/server/build/clean.js deleted file mode 100644 index 4df79e9c2f5bac864b4ac3d51baeef25a63c44d0..0000000000000000000000000000000000000000 --- a/server/build/clean.js +++ /dev/null @@ -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 }) -} diff --git a/server/build/root-module-relative-path.js b/server/build/root-module-relative-path.js deleted file mode 100644 index 54557a817aca04d4df040ec59fa8a6db1b859829..0000000000000000000000000000000000000000 --- a/server/build/root-module-relative-path.js +++ /dev/null @@ -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) -} diff --git a/server/export.js b/server/export.js index 0a88fa1bcc5da233ebebe937ccc130eff75feaa7..ba05caec90e02a8957c2cab7e12d64fc77c4fd6b 100644 --- a/server/export.js +++ b/server/export.js @@ -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, diff --git a/server/hot-reloader.js b/server/hot-reloader.js index fb4b92deb9be77bcba283fab02870b0a93ca52cd..745b93d12ef60b45c3f813b8e8a345cf4a8c3512 100644 --- a/server/hot-reloader.js +++ b/server/hot-reloader.js @@ -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 }), diff --git a/server/index.js b/server/index.js index 46b15b3a26c19adeaa9d505273436f40a22692b8..9fe619b9b82453423e92340c418d3ce0f94c5051 100644 --- a/server/index.js +++ b/server/index.js @@ -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) }, diff --git a/server/render.js b/server/render.js index 883c5a2c1fc40f8759c0813bb78ae6192bedaf70..3d306f26eebbd7ec02b3cb8fcc8e11a1671f74d6 100644 --- a/server/render.js +++ b/server/render.js @@ -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})