forked from hanford/next-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.js
24 lines (19 loc) · 750 Bytes
/
export.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
const { copy } = require('fs-extra');
const { join } = require('path');
/**
* Copy the generated service worker into the export folder.
*/
function exportSw(nextConfig) {
return async function exportPathMap(...args) {
const [defaultPathMap, { dev, distDir, outDir }] = args;
const swDest = (nextConfig.workboxOpts && nextConfig.workboxOpts.swDest) || 'service-worker.js';
if (dev) {
return defaultPathMap;
}
// Copy service worker from Next.js build dir into the export dir.
await copy(join(distDir, swDest), join(outDir, swDest));
// Run user's exportPathMap function if available.
return nextConfig.exportPathMap ? nextConfig.exportPathMap(...args) : defaultPathMap;
};
}
module.exports = exportSw;