feat: make appTemplatePath customizable (#3678)

related: #1925
This commit is contained in:
Alexander Lichter 2018-08-10 17:23:09 +02:00 committed by Clark Du
parent 75d6c4e33a
commit 960f4fe47e
6 changed files with 49 additions and 3 deletions

View File

@ -78,9 +78,13 @@ Options.from = function (_options) {
}
// If app.html is defined, set the template path to the user template
options.appTemplatePath = path.resolve(options.buildDir, 'views/app.template.html')
if (fs.existsSync(path.join(options.srcDir, 'app.html'))) {
options.appTemplatePath = path.join(options.srcDir, 'app.html')
if (options.appTemplatePath === undefined) {
options.appTemplatePath = path.resolve(options.buildDir, 'views/app.template.html')
if (fs.existsSync(path.join(options.srcDir, 'app.html'))) {
options.appTemplatePath = path.join(options.srcDir, 'app.html')
}
} else {
options.appTemplatePath = path.resolve(options.srcDir, options.appTemplatePath)
}
// Ignore publicPath on dev

View File

@ -0,0 +1,3 @@
const { buildFixture } = require('../../utils/build')
buildFixture('custom-app-template')

View File

@ -0,0 +1,3 @@
export default {
appTemplatePath: './test/mytemplate.html'
}

View File

@ -0,0 +1,3 @@
<template>
<h1>Custom!</h1>
</template>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head>
{{ HEAD }}
</head>
<body {{ BODY_ATTRS }}>
{{ APP }}
<p>My Template</p>
</body>
</html>

View File

@ -0,0 +1,23 @@
import { getPort, loadFixture, Nuxt } from '../utils'
let port
let nuxt = null
describe('custom-app-template', () => {
beforeAll(async () => {
const options = loadFixture('custom-app-template')
nuxt = new Nuxt(options)
port = await getPort()
await nuxt.listen(port, '0.0.0.0')
})
test('/', async () => {
const { html } = await nuxt.renderRoute('/')
expect(html.includes('<p>My Template</p>')).toBe(true)
expect(html.includes('<h1>Custom!</h1>')).toBe(true)
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
})
})