From fb6f5d43826500643ea3150e3b0f10f320315568 Mon Sep 17 00:00:00 2001 From: nkzawa Date: Mon, 17 Oct 2016 12:55:09 +0900 Subject: [PATCH 1/2] change build directories structure --- server/build/webpack.js | 10 +++++----- server/render.js | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/build/webpack.js b/server/build/webpack.js index 8b15b8d0..d2520cea 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -11,12 +11,12 @@ export default async function createCompiler (dir, { hotReload = false } = {}) { const entry = {} const defaultEntries = hotReload ? ['webpack/hot/only-dev-server'] : [] for (const p of pages) { - entry[join('_bundles', p)] = defaultEntries.concat(['./' + p]) + entry[join('bundles', p)] = defaultEntries.concat(['./' + p]) } - const errEntry = join('_bundles', 'pages', '_error.js') + const errorEntry = join('bundles', 'pages', '_error.js') const defaultErrorPath = resolve(__dirname, '..', '..', 'pages', '_error.js') - if (!entry[errEntry]) entry[errEntry] = defaultErrorPath + if (!entry[errorEntry]) entry[errorEntry] = defaultErrorPath const nodeModulesDir = resolve(__dirname, '..', '..', '..', 'node_modules') @@ -42,7 +42,7 @@ export default async function createCompiler (dir, { hotReload = false } = {}) { ], exclude: /node_modules/, query: { - name: '[path][name].[ext]' + name: 'dist/[path][name].[ext]' } }, { test: /\.js$/, @@ -118,7 +118,7 @@ export default async function createCompiler (dir, { hotReload = false } = {}) { }, customInterpolateName: function (url, name, opts) { if (defaultErrorPath === this.resourcePath) { - return 'pages/_error.js' + return 'dist/pages/_error.js' } return url } diff --git a/server/render.js b/server/render.js index 7e14fe7b..3ebf7703 100644 --- a/server/render.js +++ b/server/render.js @@ -16,11 +16,11 @@ export async function render (url, ctx = {}, { staticMarkup = false } = {}) { const path = getPath(url) - const mod = await requireModule(resolve(dir, '.next', 'pages', path)) + const mod = await requireModule(resolve(dir, '.next', 'dist', 'pages', path)) const Component = mod.default || mod const props = await (Component.getInitialProps ? Component.getInitialProps(ctx) : {}) - const component = await read(resolve(dir, '.next', '_bundles', 'pages', path)) + const component = await read(resolve(dir, '.next', 'bundles', 'pages', path)) const { html, css } = StyleSheetServer.renderStatic(() => { const app = createElement(App, { @@ -53,7 +53,7 @@ export async function render (url, ctx = {}, { export async function renderJSON (url, { dir = process.cwd() } = {}) { const path = getPath(url) - const component = await read(resolve(dir, '.next', '_bundles', 'pages', path)) + const component = await read(resolve(dir, '.next', 'bundles', 'pages', path)) return { component } } From a40bba954b8887a99164baa089a799bbaeb58c48 Mon Sep 17 00:00:00 2001 From: nkzawa Date: Mon, 17 Oct 2016 12:55:33 +0900 Subject: [PATCH 2/2] remove .next before compiling --- bin/next-dev | 10 +++++++--- package.json | 2 +- server/build/clean.js | 6 ++++++ server/build/index.js | 6 +++++- 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 server/build/clean.js diff --git a/bin/next-dev b/bin/next-dev index 6b7b72d5..03026270 100755 --- a/bin/next-dev +++ b/bin/next-dev @@ -2,10 +2,11 @@ import { exec } from 'child_process' import { resolve, join } from 'path' import parseArgs from 'minimist' +import { exists } from 'mz/fs' import Server from '../server' import HotReloader from '../server/hot-reloader' import webpack from '../server/build/webpack' -import { exists } from 'mz/fs' +import clean from '../server/build/clean' const argv = parseArgs(process.argv.slice(2), { alias: { @@ -26,8 +27,11 @@ const open = url => { const dir = resolve(argv._[0] || '.') -webpack(dir, { hotReload: true }) -.then(async (compiler) => { +Promise.all([ + webpack(dir, { hotReload: true }), + clean(dir) +]) +.then(async ([compiler]) => { const hotReloader = new HotReloader(compiler) const srv = new Server({ dir, dev: true, hotReloader }) await srv.start(argv.port) diff --git a/package.json b/package.json index 840dffc9..51b229b5 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "babel-preset-react": "6.16.0", "babel-runtime": "6.11.6", "cross-spawn": "4.0.2", + "del": "2.2.2", "glob-promise": "1.0.6", "gulp-benchmark": "^1.1.1", "htmlescape": "1.1.1", @@ -52,7 +53,6 @@ "devDependencies": { "babel-eslint": "^7.0.0", "babel-plugin-transform-remove-strict-mode": "0.0.2", - "del": "2.2.2", "gulp": "3.9.1", "gulp-ava": "0.14.1", "gulp-babel": "6.1.2", diff --git a/server/build/clean.js b/server/build/clean.js new file mode 100644 index 00000000..f0d0876a --- /dev/null +++ b/server/build/clean.js @@ -0,0 +1,6 @@ +import { resolve } from 'path' +import del from 'del' + +export default function clean (dir) { + return del(resolve(dir, '.next')) +} diff --git a/server/build/index.js b/server/build/index.js index f8aff5a5..9fc01134 100644 --- a/server/build/index.js +++ b/server/build/index.js @@ -1,7 +1,11 @@ import webpack from './webpack' +import clean from './clean' export default async function build (dir) { - const compiler = await webpack(dir) + const [compiler] = await Promise.all([ + webpack(dir), + clean(dir) + ]) return new Promise((resolve, reject) => { compiler.run((err, stats) => {