Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (source, map) {
const isProd = process.env.NODE_ENV === 'production'
if (!isProd) {
const file = this.resourcePath
// frontmatter changed... need to do a full reload
const cached = cache.get(file)
const parsed = parseStrippedFrontmatter(source)
if (cached &&
cached.data &&
parsed &&
parsed.data &&
JSON.stringify(cached.data) !== JSON.stringify(parsed.data)
) {
frontmatterEmitter.emit('update')
}
cache.set(file, parsed)
}
this.callback(null, '', map)
}
(
ctx.siteConfig.extraWatchFiles || []
).map(file => normalizeWatchFilePath(file, ctx.sourceDir))
)
logger.debug('watchFiles', watchFiles)
// watch config file
const configWatcher = chokidar.watch(watchFiles, {
cwd: sourceDir,
ignoreInitial: true
})
configWatcher.on('change', spawnUpdate('change'))
// also listen for frontmatter changes from markdown files
frontmatterEmitter.on('update', () => update('frontmatter or headers change'))
// resolve webpack config
let config = createClientConfig(ctx)
config
.plugin('html')
// using a fork of html-webpack-plugin to avoid it requiring webpack
// internals from an incompatible version.
.use(require('vuepress-html-webpack-plugin'), [{
template: ctx.devTemplate
}])
config
.plugin('site-data')
.use(HeadPlugin, [{
tags: ctx.siteConfig.head || []
watchFrontmatter () {
frontmatterEmitter.on('update', target => this.handleUpdate('frontmatter', target))
}