Skip to content
Permalink
Browse files

fix: create cache (#47)

  • Loading branch information...
ricardogobbosouza authored and manniL committed Feb 12, 2019
1 parent 2a0f0e3 commit 45cabaed7bfa00c2a2d8d376e46674188102f2d0
Showing with 4 additions and 13 deletions.
  1. +4 −13 src/index.js
@@ -27,16 +27,8 @@ module.exports = function module (moduleOptions) {
// sitemap-routes.json is written to dist dir on build mode
const jsonStaticRoutesPath = path.resolve(this.options.buildDir, path.join('dist', 'sitemap-routes.json'))

let staticRoutes = fs.readJsonSync(jsonStaticRoutesPath, { throws: false })
let cache = null

if (staticRoutes && !this.options.dev) {
// Create a cache for routes
cache = createCache(staticRoutes, options)
// Hydrate cache
cache.get('routes')
}

// Extend routes
this.extendRoutes(routes => {
// Map to path and filter dynamic routes
@@ -51,14 +43,13 @@ module.exports = function module (moduleOptions) {
staticRoutes = staticRoutes.filter(route => minimatch.match(route))
})

if (this.options.dev) {
// Create a cache for routes
cache = createCache(staticRoutes, options)
} else {
// Save static routes
if (!this.options.dev) {
fs.ensureDirSync(path.resolve(this.options.buildDir, 'dist'))
fs.writeJsonSync(jsonStaticRoutesPath, staticRoutes)
}

// Create a cache for routes
cache = createCache(staticRoutes, options)
})

if (options.generate) {

0 comments on commit 45cabae

Please sign in to comment.
You can’t perform that action at this time.