From 39db08c95bd6e79b64812c44650b17c92de4a4e2 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 5 May 2017 16:47:28 +0200 Subject: [PATCH 1/4] Lint --- lib/generate.js | 17 +++++++++-------- lib/webpack/helpers.js | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/generate.js b/lib/generate.js index f0e656dec2..d1efb299aa 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -100,18 +100,18 @@ export default function () { yield waitFor(n++ * self.options.generate.interval) try { var { html, error } = yield self.renderRoute(route, { _generate: true }) - if(error) { - errors.push({ type : 'handled', route, error }) + if (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) { + } 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,13 +136,14 @@ export default function () { debug(`HTML Files generated in ${duration}s`) if (errors.length) { - console.error('==== Error report ==== \n' + errors.map( ({type, route, error}) => { - if(type === 'unhandled') { + 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/webpack/helpers.js b/lib/webpack/helpers.js index 9681212994..3a43041095 100755 --- a/lib/webpack/helpers.js +++ b/lib/webpack/helpers.js @@ -1,10 +1,10 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin' -export function extractStyles(ext) { +export function extractStyles (ext) { return !this.dev && !!this.options.build.extractCSS && this.options.build.extractCSS[ext] !== false } -export function styleLoader(ext, loader = []) { +export function styleLoader (ext, loader = []) { if (!extractStyles.call(this, ext)) { return ['vue-style-loader', 'css-loader'].concat(loader) } From 6178527177ca633570d010fb35c7bfb6a4174ecc Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 5 May 2017 16:47:50 +0200 Subject: [PATCH 2/4] Improve logs --- lib/build.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 } From 7f1bf3d5f0f30744a16984d008139df0b4a4426a Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 5 May 2017 16:48:04 +0200 Subject: [PATCH 3/4] Fix typo --- lib/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 333e3cf13aeaa76b5c6d28e3994820ae0fd0fd64 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 5 May 2017 16:48:12 +0200 Subject: [PATCH 4/4] Add other extensions --- lib/webpack/client.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webpack/client.config.js b/lib/webpack/client.config.js index f4054c05e0..f5f7857383 100644 --- a/lib/webpack/client.config.js +++ b/lib/webpack/client.config.js @@ -64,7 +64,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) ) } }),