-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const path = require('path');
const getCacheDirs = (constants) => [
constants.PUBLISH_DIR,
path.normalize(`${constants.PUBLISH_DIR}/../.cache`),
];
module.exports = {
async onPreBuild({ constants, utils }) {
// print a helpful message if the publish dir is misconfigured
if (process.cwd() === constants.PUBLISH_DIR) {
utils.build.failBuild(
`Gatsby sites must publish the public directory, but your site’s publish directory is set to “${constants.PUBLISH_DIR}”. Please set your publish directory to your Gatsby site’s public directory.`,
);
}
const package = require(process.cwd() + "/package.json");
const cacheDirs = getCacheDirs(constants).concat(package.workspaces.map(w => (w + "/.cache")), package.workspaces.map(w => (w + "/public")));
if (await utils.cache.restore(cacheDirs)) {
console.log('Found a Gatsby cache. We’re about to go FAST. ⚡️');
} else {
console.log('No Gatsby cache found. Building fresh.');
}
},
async onPostBuild({ constants, utils }) {
const cacheDirs = getCacheDirs(constants);
if (await utils.cache.save(cacheDirs)) {
console.log('Stored the Gatsby cache to speed up future builds.');
} else {
console.log('No Gatsby build found.');
}
},
};