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