Skip to content

Commit 38b3468

Browse files
committed
feat($core): config the dev and ssr template. (close: #733)
1 parent eff7949 commit 38b3468

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

packages/@vuepress/core/lib/build.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
2525
return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
2626
}
2727
await fs.remove(outDir)
28+
logger.debug('Dist directory: ' + chalk.gray(path.resolve(outDir)))
2829

2930
let clientConfig = createClientConfig(options, cliOptions).toConfig()
3031
let serverConfig = createServerConfig(options, cliOptions).toConfig()
@@ -56,7 +57,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
5657
runInNewContext: false,
5758
inject: false,
5859
shouldPrefetch: options.siteConfig.shouldPrefetch || (() => true),
59-
template: await fs.readFile(path.resolve(__dirname, 'app/index.ssr.html'), 'utf-8')
60+
template: await fs.readFile(options.ssrTemplate, 'utf-8')
6061
})
6162

6263
// pre-render head tags from user config

packages/@vuepress/core/lib/dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
6565
// using a fork of html-webpack-plugin to avoid it requiring webpack
6666
// internals from an incompatible version.
6767
.use(require('vuepress-html-webpack-plugin'), [{
68-
template: path.resolve(__dirname, 'app/index.dev.html')
68+
template: options.devTemplate
6969
}])
7070

7171
config

packages/@vuepress/core/lib/prepare/AppContext.js

+25
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = class AppContext {
4848
*/
4949
async process () {
5050
this.normalizeHeadTagUrls()
51+
this.resolveTemplates()
5152
await this.resolveTheme()
5253
this.resolvePlugins()
5354

@@ -124,6 +125,30 @@ module.exports = class AppContext {
124125
}
125126
}
126127

128+
/**
129+
* Make template configurable
130+
*/
131+
resolveTemplates () {
132+
let { ssrTemplate, devTemplate } = this.siteConfig
133+
const templateDir = path.resolve(this.vuepressDir, 'templates')
134+
if (!devTemplate) {
135+
devTemplate = path.resolve(templateDir, 'dev.html')
136+
if (!fs.existsSync(devTemplate)) {
137+
devTemplate = path.resolve(__dirname, '../app/index.dev.html')
138+
}
139+
}
140+
if (!ssrTemplate) {
141+
ssrTemplate = path.resolve(templateDir, 'ssr.html')
142+
if (!fs.existsSync(ssrTemplate)) {
143+
ssrTemplate = path.resolve(__dirname, '../app/index.ssr.html')
144+
}
145+
}
146+
logger.debug('SSR Template File: ' + chalk.gray(ssrTemplate))
147+
logger.debug('DEV Template File: ' + chalk.gray(devTemplate))
148+
this.devTemplate = devTemplate
149+
this.ssrTemplate = ssrTemplate
150+
}
151+
127152
/**
128153
* Find all page source files located in sourceDir
129154
* @returns {Promise<void>}

0 commit comments

Comments
 (0)