Skip to content

Commit

Permalink
handled not-generated pages, pushing clean build
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Jun 6, 2019
1 parent 5b4e4fc commit 90afede
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 25 deletions.
21 changes: 21 additions & 0 deletions empty-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require('fs-extra')
const path = require('path')

const isProduction = process.env.NODE_ENV === 'PRODUCTION'

const CACHE_PATH = isProduction
? path.join('/', 'opt', 'build', 'cache', 'nuxt_build') // Netlify cache path
: path.resolve(__dirname, '.nuxt_build')

async function emptyCache() {
try {
await fs.emptyDir(CACHE_PATH)
} catch (e) {
console.log(e)
}
}

;(async () => {
// code goes here
await emptyCache()
})()
5 changes: 1 addition & 4 deletions layouts/error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<div class="container mt-md">
<div v-if="error.statusCode === 404">
<h1 class="is-size-2 mb-md">Page not found.</h1>
<div>
The link you followed is probably broken, or the page has been removed. You are now being redirected to the main
careers page.
</div>
<div>The link you followed is probably broken, or the page has been removed.</div>
</div>
<h1 v-else>An error occurred. Please Try Later.</h1>
</div>
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

[context.master]
publish = "dist"
command = "npm run incremental-build"
command = "npm run clean-build"
environment = { NODE_ENV = "PRODUCTION"}
10 changes: 5 additions & 5 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { cacheAndCopy } = require('./cache-me')
const mockRoutes = require('./route-mock')
const { initialRoutes, additionalRoutes, initialTotalRoutes, additionalTotalRoutes } = mockRoutes

const routesToGenerate = additionalRoutes
const routesList = process.env.INITIAL_BUILD === 'true' ? initialTotalRoutes : additionalTotalRoutes
const routesToGenerate = initialRoutes
const routesList = initialTotalRoutes
const isDev = process.env.DEPLOY_ENV === 'DEV'

module.exports = {
Expand Down Expand Up @@ -57,14 +57,15 @@ module.exports = {
*/
generate: {
fallback: true,
routes: function() {
routes: function(callback) {
const routes = routesToGenerate.concat({
route: '/',
payload: {
routesList: routesList
}
})
return routes
console.log(routes)
callback(null, routes)
}
},
/*
Expand Down Expand Up @@ -115,7 +116,6 @@ module.exports = {
},
hooks: {
generate: {
fallback: true,
// async before() {
// console.log('this bef orehook..')
// await putNuxtClientBack()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"start": "nuxt start",
"clean-all": "rm -rf .nuxt; rm -rf dist;rm -rf .nuxt_build;",
"generate": "nuxt generate",
"clean-build":"node empty-cache; npm run generate;",
"generate-netlify": "DEPLOY_ENV=PRODUCTION nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"lintfix": "eslint --fix --ext .js,.vue --ignore-path .gitignore .",
Expand Down
12 changes: 11 additions & 1 deletion pages/_sub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@
</template>

<script>
const { initialRoutes, additionalRoutes, initialTotalRoutes, additionalTotalRoutes } = require('../route-mock')
export default {
async asyncData({ params, error, payload }) {
if (payload) return { contents: payload.content }
else return { contents: 'contents for sub page' }
else {
try {
const thisone = additionalTotalRoutes.filter(e => e.route === params.sub)[0]
if (thisone) return { contents: thisone.payload.content }
else throw 'error'
} catch (e) {
throw e
}
}
}
}
</script>
Expand Down
24 changes: 10 additions & 14 deletions route-mock.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
const initialRoutes = [
{
route: 'subroute-a',
payload: {
content: 'this is subroute a contents'
}
},
{
route: 'subroute-b',
const routesNum = 10

const initialRoutes = Array.apply(null, { length: routesNum - 1 })
.map(Number.call, Number)
.map(e => ({
route: `subroute-${e}`,
payload: {
content: 'this is subroute b contents'
content: `this is subroute ${e} contents`
}
}
]
}))

const additionalRoutes = [
{
route: 'subroute-d',
route: `subroute-${routesNum - 1}`,
payload: {
content: 'this is subroute d contents'
content: `this is subroute ${routesNum - 1} contents`
}
}
]
Expand Down

0 comments on commit 90afede

Please sign in to comment.