mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
Allow override anything using a file with same name in srcDir/app
This commit is contained in:
parent
e9d998e522
commit
51618bef29
29
lib/build.js
29
lib/build.js
@ -241,13 +241,27 @@ async function generateRoutesAndFiles () {
|
||||
if (this.options.store) {
|
||||
templatesFiles.push('store.js')
|
||||
}
|
||||
// Resolve all internal template files relative to app directory
|
||||
templatesFiles = templatesFiles.map(file => { return {src: r(__dirname, 'app', file), dst: file} })
|
||||
// Resolve template files
|
||||
templatesFiles = templatesFiles.map(file => {
|
||||
// Allow override anything using a file with same name in srcDir/app
|
||||
const customPath = r(this.srcDir, 'app', file)
|
||||
const customFileExists = fs.existsSync(customPath)
|
||||
return {
|
||||
src: customFileExists ? customPath : r(__dirname, 'app', file),
|
||||
dst: file,
|
||||
custom: customFileExists
|
||||
}
|
||||
})
|
||||
// Add external template files (used in modules)
|
||||
if (Array.isArray(this.options.build.templates)) {
|
||||
templatesFiles = templatesFiles.concat(this.options.build.templates)
|
||||
templatesFiles = templatesFiles.concat(this.options.build.templates.map(t => {
|
||||
return Object.assign({custom: true}, t)
|
||||
}))
|
||||
}
|
||||
let moveTemplates = templatesFiles.map(({src, dst, options}) => {
|
||||
let moveTemplates = templatesFiles.map(({src, dst, options, custom}) => {
|
||||
// Add template to watchers
|
||||
this.options.build.watch.push(src)
|
||||
// Render template to dst
|
||||
return readFile(src, 'utf8')
|
||||
.then((fileContent) => {
|
||||
const template = _.template(fileContent, {
|
||||
@ -257,7 +271,10 @@ async function generateRoutesAndFiles () {
|
||||
}
|
||||
})
|
||||
const content = template(Object.assign({}, templateVars, {
|
||||
options: options || {}
|
||||
options: options || {},
|
||||
custom,
|
||||
src,
|
||||
dst
|
||||
}))
|
||||
const path = r(this.dir, '.nuxt', dst)
|
||||
return writeFile(path, content, 'utf8')
|
||||
@ -518,7 +535,7 @@ function watchPages () {
|
||||
})
|
||||
/* istanbul ignore next */
|
||||
const refreshFiles = _.debounce(async () => {
|
||||
await generateRoutesAndFiles.bind(this)
|
||||
await generateRoutesAndFiles.call(this)
|
||||
}, 200)
|
||||
// Watch for internals
|
||||
this.pagesFilesWatcher = chokidar.watch(patterns, options)
|
||||
|
Loading…
Reference in New Issue
Block a user