fix(builder): preserve templateVars.options in templates (#5730) (#5776)

This commit is contained in:
Xin Du (Clark) 2019-05-21 19:11:34 +01:00 committed by Pooya Parsa
parent 77a0e80e09
commit b49dc0fe99

View File

@ -498,7 +498,9 @@ export default class Builder {
// Interpret and move template files to .nuxt/ // Interpret and move template files to .nuxt/
await Promise.all( await Promise.all(
templateFiles.map(async ({ src, dst, options, custom }) => { templateFiles.map(async (templateFile) => {
const { src, dst, custom } = templateFile
// Add custom templates to watcher // Add custom templates to watcher
if (custom) { if (custom) {
this.options.build.watch.push(src) this.options.build.watch.push(src)
@ -510,15 +512,15 @@ export default class Builder {
try { try {
const templateFunction = template(fileContent, templateOptions) const templateFunction = template(fileContent, templateOptions)
content = stripWhitespace( content = stripWhitespace(
templateFunction( templateFunction({
Object.assign({}, templateVars, { ...templateVars,
options: options || {}, ...templateFile,
custom, options: {
src, ...templateVars.options,
dst ...templateFile.options
}
}) })
) )
)
} catch (err) { } catch (err) {
throw new Error(`Could not compile template ${src}: ${err.message}`) throw new Error(`Could not compile template ${src}: ${err.message}`)
} }