add generate html template config

This commit is contained in:
XIANG\xiang 2017-08-07 01:28:25 +08:00
parent 1c527c2db6
commit 75f3e9637e
2 changed files with 19 additions and 3 deletions

View File

@ -132,6 +132,19 @@ export default class Generator extends Tapable {
return _.values(routeMap) return _.values(routeMap)
} }
buildHtmlFilePath (route) {
const { html = {} } = this.options.generate
let {
useRouteName = false,
fileName = 'index',
extension = 'html'
} = html
extension = extension ? `.${extension}` : ''
const name = useRouteName ? (route === '/' ? 'index' : '') : fileName
const path = useRouteName ? `${route}${name}${extension}` : join(route, sep, `${name}${extension}`)// /about -> /about/index.html
return (route === '/404') ? `/404${extension}` : path // /404 -> /404.html
}
async generateRoute ({route, payload = {}, errors = []}) { async generateRoute ({route, payload = {}, errors = []}) {
let html let html
@ -154,9 +167,7 @@ export default class Generator extends Tapable {
errors.push({ type: 'unhandled', route, error: minifyErr }) errors.push({ type: 'unhandled', route, error: minifyErr })
} }
} }
let path = this.buildHtmlFilePath(route)
let path = join(route, sep, 'index.html') // /about -> /about/index.html
path = (path === '/404/index.html') ? '/404.html' : path // /404 -> /404.html
debug('Generate file: ' + path) debug('Generate file: ' + path)
path = join(this.distPath, path) path = join(this.distPath, path)

View File

@ -149,6 +149,11 @@ Options.defaults = {
sortClassName: true, sortClassName: true,
trimCustomFragments: true, trimCustomFragments: true,
useShortDoctype: true useShortDoctype: true
},
html: {
useRouteName: false, // if set ture, will use the last route path as html file name, but replace route `/` with `/index`.
fileName: 'index', // the html template file name, default 'index'.
extension: 'html' // the html template extension type, default `html`. also can be set 'php' or jsp' or others.
} }
}, },
env: {}, env: {},