diff --git a/lib/build.js b/lib/build.js index c9fcc9d2e6..fe56ac0704 100644 --- a/lib/build.js +++ b/lib/build.js @@ -425,11 +425,7 @@ function webpackWatchAndUpdate () { if (err) throw err const bundleExists = serverFS.existsSync(bundlePath) const manifestExists = clientFS.existsSync(manifestPath) - if (!bundleExists) { - debug('Waiting for server bundle...') - } else if (!manifestExists) { - debug('Waiting for client manifest...') - } else { + if (bundleExists && manifestExists) { const bundle = serverFS.readFileSync(bundlePath, 'utf8') const manifest = clientFS.readFileSync(manifestPath, 'utf8') createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest)) @@ -463,11 +459,13 @@ function webpackRunServer () { const bundlePath = join(serverConfig.output.path, 'server-bundle.json') const manifestPath = join(serverConfig.output.path, 'client-manifest.json') readFile(bundlePath, 'utf8') - .then(bundle => readFile(manifestPath, 'utf8') + .then(bundle => { + readFile(manifestPath, 'utf8') .then(manifest => { createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest)) resolve() - })) + }) + }) }) }) } @@ -485,8 +483,10 @@ function createRenderer (bundle, manifest) { this.renderer = createBundleRenderer(bundle, Object.assign({ cache: cacheConfig, clientManifest: manifest, - runInNewContext: false - }, this.options.ssr)) + runInNewContext: false, + inject: false, + baseDir: this.options.dir + }, this.options.build.ssr)) this.renderToString = pify(this.renderer.renderToString) this.renderToStream = this.renderer.renderToStream } diff --git a/lib/generate.js b/lib/generate.js index 4cb1f2b398..d1efb299aa 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -101,17 +101,17 @@ export default function () { try { var { html, error } = yield self.renderRoute(route, { _generate: true }) if (error) { - errors.push({type: 'handled', route, error}) + errors.push({ type: 'handled', route, error }) } } catch (err) { - errors.push({type: 'unhandled', route, error: err}) + errors.push({ type: 'unhandled', route, error: err }) return } try { var minifiedHtml = minify(html, self.options.generate.minify) } catch (err) { let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`) - errors.push({type: 'unhandled', route, error: minifyErr}) + errors.push({ type: 'unhandled', route, error: minifyErr }) return } var path = join(route, sep, 'index.html') // /about -> /about/index.html @@ -136,14 +136,14 @@ export default function () { debug(`HTML Files generated in ${duration}s`) if (errors.length) { - /* eslint-disable no-console */ - console.error('==== Error report ==== \n' + errors.map(({type, route, error}) => { + const report = errors.map(({ type, route, error }) => { if (type === 'unhandled') { return `Route: '${route}'\n${error.stack}` } else { return `Route: '${route}' thrown an error: \n` + JSON.stringify(error) } - }).join('\n\n')) + }) + console.error('==== Error report ==== \n' + report).join('\n\n') // eslint-disable-line no-console } return this }) diff --git a/lib/render.js b/lib/render.js index 5434d1c66d..4b5420123d 100644 --- a/lib/render.js +++ b/lib/render.js @@ -93,7 +93,7 @@ export function renderRoute (url, context = {}) { // Add url and isSever to the context context.url = url context.isServer = true - // Call renderToSting from the bundleRenderer and generate the HTML (will update the context as well) + // Call renderToString from the bundleRenderer and generate the HTML (will update the context as well) const self = this return co(function * () { let APP = yield self.renderToString(context) diff --git a/lib/webpack/client.config.js b/lib/webpack/client.config.js index fda3296344..930b5646d9 100644 --- a/lib/webpack/client.config.js +++ b/lib/webpack/client.config.js @@ -62,7 +62,7 @@ export default function () { // If it's inside node_modules /node_modules/.test(module.context) && // Do not externalize if the request is a CSS file - !/\.css$/.test(module.request) + !/\.(css|less|scss|sass|styl|stylus)$/.test(module.request) ) } }),