dev: Improve template debugging in development

This commit is contained in:
Sébastien Chopin 2017-10-13 22:20:16 +02:00
parent a5e16d2fe6
commit 031b0d58c8
1 changed files with 22 additions and 17 deletions

View File

@ -335,23 +335,28 @@ export default class Builder extends Tapable {
this.options.build.watch.push(src) this.options.build.watch.push(src)
// Render template to dst // Render template to dst
const fileContent = await readFile(src, 'utf8') const fileContent = await readFile(src, 'utf8')
const template = _.template(fileContent, { let content
imports: { try {
serialize, const template = _.template(fileContent, {
hash, imports: {
r, serialize,
wp, hash,
wChunk, r,
resolvePath: this.nuxt.resolvePath.bind(this.nuxt), wp,
relativeToBuild: this.relativeToBuild wChunk,
} resolvePath: this.nuxt.resolvePath.bind(this.nuxt),
}) relativeToBuild: this.relativeToBuild
const content = template(Object.assign({}, templateVars, { }
options: options || {}, })
custom, content = template(Object.assign({}, templateVars, {
src, options: options || {},
dst custom,
})) src,
dst
}))
} catch (err) {
throw new Error(`Could not compile template ${src}: ${err.message}`)
}
const path = r(this.options.buildDir, dst) const path = r(this.options.buildDir, dst)
// Ensure parent dir exits // Ensure parent dir exits
await mkdirp(dirname(path)) await mkdirp(dirname(path))