提交 3871f4a1 编写于 作者: U ULIVZ

feat: cache option (boolean | absolute path | relative path)

It also close #993 via including siteConfig.extendMarkdown & siteConfig.markdown.extendMarkdown to cacheIdentifier.
上级 bfd4d02e
......@@ -7,6 +7,7 @@
const createMarkdown = require('./createMarkdown')
const loadConfig = require('./loadConfig')
const loadTheme = require('./loadTheme')
const { getCacheLoaderOptions } = require('./CacheLoader')
const {
fs, path, logger, chalk, globby, sort,
datatypes: { isFunction },
......@@ -73,6 +74,7 @@ module.exports = class AppContext {
*/
async process () {
this.resolveCacheLoaderOptions()
this.normalizeHeadTagUrls()
await this.resolveTheme()
this.resolveTemplates()
......@@ -174,6 +176,14 @@ module.exports = class AppContext {
}
}
/**
* Resolve options of cache loader.
*/
resolveCacheLoaderOptions () {
Object.assign(this, (getCacheLoaderOptions(this.siteConfig, this.cliOptions, this.cwd, this.isProd)))
}
/**
* Make template configurable
*
......
'use strict'
/**
* Module dependencies.
*/
const {
path, toAbsolutePath, chalk, logger,
datatypes: { isString, isBoolean }
} = require('@vuepress/shared-utils')
/**
* Get cache directory and cache identifier via config.
* @param {object} siteConfig
* @param {object} cliOptions
*/
exports.getCacheLoaderOptions = function (siteConfig, cliOptions, cwd, isProd) {
const defaultCacheDirectory = path.resolve(__dirname, '../../node_modules/.cache/vuepress')
let cache = cliOptions.cache || siteConfig.cache || defaultCacheDirectory
if (isBoolean(cache)) {
if (cache === true) {
cache = defaultCacheDirectory
}
} else if (!isString(cache)) {
throw new Error(`expected cache option to be string or boolean, but got ${typeof cache}`)
}
const cacheDirectory = toAbsolutePath(cache, cwd)
const cacheIdentifier = JSON.stringify({
vuepress: require('../../package.json').version,
'cache-loader': require('cache-loader/package.json').version,
'vue-loader': require('cache-loader/package.json').version,
isProd,
config: (
(
siteConfig.markdown
? JSON.stringify(siteConfig.markdown)
: ''
) +
(
siteConfig.markdown && siteConfig.markdown.extendMarkdown
? siteConfig.markdown.extendMarkdown.toString()
: ''
) +
(
siteConfig.extendMarkdown
? siteConfig.extendMarkdown.toString()
: ''
) +
(siteConfig.chainWebpack || '').toString() +
(siteConfig.configureWebpack || '').toString()
)
})
logger.debug('\nCache directory: ' + chalk.gray(cacheDirectory))
logger.debug('\nCache identifier : ' + chalk.gray(cacheIdentifier))
return { cacheDirectory, cacheIdentifier }
}
......@@ -4,7 +4,7 @@
* Module dependencies.
*/
const { fs, path, logger, chalk } = require('@vuepress/shared-utils')
const { fs, path, logger } = require('@vuepress/shared-utils')
/**
* Expose createBaseConfig method.
......@@ -18,6 +18,8 @@ module.exports = function createBaseConfig ({
themePath,
markdown,
tempPath,
cacheDirectory,
cacheIdentifier,
cliOptions: {
debug,
cache
......@@ -73,29 +75,12 @@ module.exports = function createBaseConfig ({
config.module
.noParse(/^(vue|vue-router|vuex|vuex-router-sync)$/)
let cacheDirectory
if (cache && typeof cache === 'string') {
cacheDirectory = path.resolve(cache)
} else {
cacheDirectory = path.resolve(__dirname, '../../node_modules/.cache/vuepress')
}
logger.debug('\nCache directory: ' + chalk.gray(cacheDirectory))
if (!cache) {
if (cache === false) {
logger.tip('\nClean cache...\n')
fs.emptyDirSync(cacheDirectory)
}
const cacheIdentifier = JSON.stringify({
vuepress: require('../../package.json').version,
'cache-loader': require('cache-loader/package.json').version,
'vue-loader': require('cache-loader/package.json').version,
isProd,
isServer,
config: (
(siteConfig.markdown ? JSON.stringify(siteConfig.markdown) : '') +
(siteConfig.chainWebpack || '').toString() +
(siteConfig.configureWebpack || '').toString()
)
})
cacheIdentifier += `isServer:${isServer}`
function applyVuePipeline (rule) {
rule
......
......@@ -33,3 +33,4 @@ exports.hash = require('hash-sum')
exports.fallback = require('./lib/fallback')
exports.slugify = require('./lib/slugify')
exports.tryChain = require('./lib/tryChain')
exports.toAbsolutePath = require('./lib/toAbsolutePath')
'use strict'
/**
* Module dependencies.
*/
const path = require('upath')
/**
* Normalize path request to absolute path.
*/
module.exports = function toAbsolutePath (raw, cwd = process.cwd()) {
if (path.isAbsolute(raw)) {
return raw
}
return path.resolve(cwd, raw)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册