From 90afede9ce090ab122263fd8407057a86fabe745 Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Thu, 6 Jun 2019 16:48:14 -0400 Subject: [PATCH] handled not-generated pages, pushing clean build --- empty-cache.js | 21 +++++++++++++++++++++ layouts/error.vue | 5 +---- netlify.toml | 2 +- nuxt.config.js | 10 +++++----- package.json | 1 + pages/_sub.vue | 12 +++++++++++- route-mock.js | 24 ++++++++++-------------- 7 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 empty-cache.js diff --git a/empty-cache.js b/empty-cache.js new file mode 100644 index 0000000..403b6d1 --- /dev/null +++ b/empty-cache.js @@ -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() +})() diff --git a/layouts/error.vue b/layouts/error.vue index 02d4510..1c26cdb 100644 --- a/layouts/error.vue +++ b/layouts/error.vue @@ -2,10 +2,7 @@

Page not found.

-
- The link you followed is probably broken, or the page has been removed. You are now being redirected to the main - careers page. -
+
The link you followed is probably broken, or the page has been removed.

An error occurred. Please Try Later.

diff --git a/netlify.toml b/netlify.toml index 1ed5658..a9dd73a 100644 --- a/netlify.toml +++ b/netlify.toml @@ -11,5 +11,5 @@ [context.master] publish = "dist" - command = "npm run incremental-build" + command = "npm run clean-build" environment = { NODE_ENV = "PRODUCTION"} \ No newline at end of file diff --git a/nuxt.config.js b/nuxt.config.js index 7d557ea..d7e2d0a 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -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 = { @@ -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) } }, /* @@ -115,7 +116,6 @@ module.exports = { }, hooks: { generate: { - fallback: true, // async before() { // console.log('this bef orehook..') // await putNuxtClientBack() diff --git a/package.json b/package.json index decab15..1c753b5 100644 --- a/package.json +++ b/package.json @@ -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 .", diff --git a/pages/_sub.vue b/pages/_sub.vue index 82063e5..c6994f2 100644 --- a/pages/_sub.vue +++ b/pages/_sub.vue @@ -12,10 +12,20 @@ diff --git a/route-mock.js b/route-mock.js index dbfe53a..844044c 100644 --- a/route-mock.js +++ b/route-mock.js @@ -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` } } ]