Skip to content

Commit

Permalink
added cache logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Jun 4, 2019
1 parent 2ac7bfa commit c134b22
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
33 changes: 33 additions & 0 deletions cache-me.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const fs = require('fs-extra')
const Rsync = require('rsync')

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')

const BUILD_PATH = path.resolve(__dirname, 'dist')

var rsync = new Rsync()
.shell('ssh')
.flags('azq')
.source(BUILD_PATH)
.destination(CACHE_PATH);

function cacheFinalFiles() {
fs.copy((BUILD_PATH, CACHE_PATH)
.then(() => console.log('successssss'))
.catch(err => console.error(err))
}

fs.ensureDir(CACHE_PATH)
.then(() => {
rsync.execute(function(error, code, cmd) {
// we're done
if(!error) {
fs.copy(CACHE_PATH, BUILD_PATH)
.then(() => cacheFinalFiles())
.catch(err => console.error(err))
}
})
})
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[build]
publish = "dist"
command = "npm run generate -- --baseURL $DEPLOY_PRIME_URL"
command = "npm run incremental-build -- --baseURL $DEPLOY_PRIME_URL"

[context.master]
publish = "dist"
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
"private": true,
"scripts": {
"initial-build": "INITIAL_BUILD=true nuxt generate",
"mock-cache-dir": "mkdir cache-mock; mv dist cache-mock/dist; mv .nuxt cache-mock/.nuxt",
"incremental-build": "mv cache-mock/.nuxt .nuxt && INITIAL_BUILD=false nuxt generate --no-build",
"merge": "rsync -avz dist/ cache-mock/dist",
"incremental-build": "INITIAL_BUILD=false nuxt generate --no-build; node cache-me;",
"dev": "DEPLOY_ENV=DEV nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt 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 .",
"precommit": "npm run lint"
Expand All @@ -25,15 +24,18 @@
"devDependencies": {
"babel-eslint": "^10.0.1",
"babel-plugin-dynamic-import-node": "^2.2.0",
"cache-me-outside": "0.0.10",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-vue": "5.0.0-beta.4",
"fs-extra": "^8.0.1",
"node-sass": "^4.9.3",
"nuxt-purgecss": "^0.2.1",
"prettier": "1.15.2",
"rsync": "^0.6.1",
"sass-loader": "^7.1.0"
}
}

0 comments on commit c134b22

Please sign in to comment.