mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Try incremental builds
This commit is contained in:
parent
522a1651c3
commit
e18262f422
4 changed files with 177 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ import { promises as fs } from 'fs'
|
|||
|
||||
import pkg from './package'
|
||||
|
||||
const { cacheAndCopy } = require('./cache-me.js')
|
||||
|
||||
export default {
|
||||
target: 'static',
|
||||
|
|
@ -19,9 +20,14 @@ export default {
|
|||
// build: {
|
||||
// before: storeAppLists
|
||||
// },
|
||||
// generate: {
|
||||
// before: storeAppLists
|
||||
// }
|
||||
generate: {
|
||||
// before: storeAppLists
|
||||
async done() {
|
||||
console.log('Starting Netlify Cache')
|
||||
await cacheAndCopy()
|
||||
console.log('Finished Netlify Cache')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
generate: {
|
||||
|
|
@ -32,11 +38,74 @@ export default {
|
|||
'assets'
|
||||
]
|
||||
},
|
||||
routes() {
|
||||
return fs.readFile('./static/nuxt-endpoints.json', 'utf-8')
|
||||
async routes () {
|
||||
|
||||
const additionalRoutes = []
|
||||
const oldRoutesJsonPath = './dist/nuxt-endpoints.json'
|
||||
|
||||
const noOldRoutesFound = await fs.stat( './dist/index.html' )
|
||||
.then(stats => {
|
||||
console.log( 'stats', stats )
|
||||
return false
|
||||
})
|
||||
.catch(() => true)
|
||||
|
||||
const freshRoutesList = await fs.readFile('./static/nuxt-endpoints.json', 'utf-8')
|
||||
.then( endpointsJson => {
|
||||
return JSON.parse(endpointsJson)
|
||||
})
|
||||
|
||||
if ( noOldRoutesFound ) {
|
||||
console.log('No old routes found: Building all routes')
|
||||
return freshRoutesList
|
||||
}
|
||||
console.log('Old routes found')
|
||||
|
||||
// Get routes from previous build
|
||||
const oldRoutesList = await fs.readFile(oldRoutesJsonPath, 'utf-8')
|
||||
.then( endpointsJson => {
|
||||
return JSON.parse(endpointsJson)
|
||||
})
|
||||
|
||||
// if there are more old routes
|
||||
// then rebuild from scratch
|
||||
if ( oldRoutesList.length > freshRoutesList.length ) {
|
||||
console.log('More old routes than current ones: Building all routes')
|
||||
return freshRoutesList
|
||||
}
|
||||
console.log('oldRoutesList.length', oldRoutesList.length)
|
||||
console.log('freshRoutesList.length', freshRoutesList.length)
|
||||
|
||||
// Store old routes into set
|
||||
// so we can quickly compare them
|
||||
const oldRoutesSet = new Map( oldRoutesList.map( endpoint => [ endpoint.route, endpoint.payload ] ) )
|
||||
|
||||
// Look through fresh routes and store any that are new
|
||||
for ( const routeFromFreshList of freshRoutesList ) {
|
||||
// If the route in not in old routes
|
||||
// then regenerate this route
|
||||
if ( !oldRoutesSet.has( routeFromFreshList.route ) || JSON.stringify(oldRoutesSet.get( routeFromFreshList.route )) !== JSON.stringify(routeFromFreshList.payload) ) {
|
||||
console.log( 'Found new route', routeFromFreshList.route )
|
||||
additionalRoutes.push( routeFromFreshList )
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
const payloadChanged = JSON.stringify(oldRoutesSet.get( routeFromFreshList.route )) !== JSON.stringify(routeFromFreshList.payload)
|
||||
|
||||
// If the route payload changed
|
||||
// then regenerate this route
|
||||
if ( payloadChanged ) {
|
||||
console.log( 'Route payload changed', routeFromFreshList.route )
|
||||
additionalRoutes.push( routeFromFreshList )
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
console.log( 'additionalRoutes', additionalRoutes.length )
|
||||
|
||||
return additionalRoutes
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -149,7 +218,7 @@ export default {
|
|||
** Build configuration
|
||||
*/
|
||||
build: {
|
||||
parallel: true,
|
||||
// parallel: true,
|
||||
// hardSource: true,
|
||||
cache: true,
|
||||
html: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue