forked from ragingwind/next-manifest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (49 loc) · 1.4 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const {resolve} = require('path');
const pwaManifest = require('@pwa/manifest');
const pwaManifestIcons = require('@pwa/manifest-icons');
const makeManifest = async manifest => {
const m = await pwaManifest({
"background_color": "#FFFFFF",
"theme_color": "#FFFFFF",
"start_url": "/?utm_source=web_app_manifest",
...manifest
});
if (manifest.icons && manifest.icons.src) {
m.icons = await pwaManifestIcons({
src: manifest.icons.src,
cache: manifest.icons.cache || false,
output: resolve(process.cwd(), `./static/manifest/icons`),
publicPath: '/static/manifest/icons/',
sizes: manifest.icons.sizes || [192, 512]
});
}
await pwaManifest.write('./static/manifest/', m);
}
module.exports = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
const {
isServer,
dev,
buildId,
defaultLoaders,
config: {
distDir
}
} = options
if (!defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
}
const {webpack, manifest} = nextConfig;
if (!isServer && !dev) {
makeManifest(manifest);
}
if (typeof webpack === 'function') {
return webpack(config, options);
}
return config;
}
})
}