From 031b0d58c89b6f20118742e88e613541e10b4b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Fri, 13 Oct 2017 22:20:16 +0200 Subject: [PATCH] dev: Improve template debugging in development --- lib/builder/builder.js | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 655b3a85f9..25b280796e 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -335,23 +335,28 @@ export default class Builder extends Tapable { this.options.build.watch.push(src) // Render template to dst const fileContent = await readFile(src, 'utf8') - const template = _.template(fileContent, { - imports: { - serialize, - hash, - r, - wp, - wChunk, - resolvePath: this.nuxt.resolvePath.bind(this.nuxt), - relativeToBuild: this.relativeToBuild - } - }) - const content = template(Object.assign({}, templateVars, { - options: options || {}, - custom, - src, - dst - })) + let content + try { + const template = _.template(fileContent, { + imports: { + serialize, + hash, + r, + wp, + wChunk, + resolvePath: this.nuxt.resolvePath.bind(this.nuxt), + relativeToBuild: this.relativeToBuild + } + }) + content = template(Object.assign({}, templateVars, { + options: options || {}, + custom, + src, + dst + })) + } catch (err) { + throw new Error(`Could not compile template ${src}: ${err.message}`) + } const path = r(this.options.buildDir, dst) // Ensure parent dir exits await mkdirp(dirname(path))