-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
67 lines (55 loc) · 1.93 KB
/
next.config.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
60
61
62
63
64
65
66
67
const { join } = require("path")
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
const { InjectManifest } = require("workbox-webpack-plugin")
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
poweredByHeader: false,
images: {
domains: ["firebasestorage.googleapis.com"],
},
}
const withWorkbox = (nextConfig = {}) => {
return {
...nextConfig,
webpack(config, options) {
if (typeof nextConfig.webpack === "function") {
config = nextConfig.webpack(config, options)
}
const {
dev,
isServer,
config: { workbox: { dest = "public", force = false, modifyURLPrefix = {}, swDest = "sw.js", swSrc = false, ...workboxOptions } = {} },
} = options
if (isServer || !force) {
console.log("> Progressive Web App is disabled")
return config
}
const swDestPath = join(options.dir, dest, swDest)
console.log("> Progressive web app is enabled using Workbox")
console.log(`> Service worker destination path: "${swDestPath}"`)
config.plugins.push(
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [swDestPath, `${swDestPath}.map`],
})
)
if (swSrc) {
const swSrcPath = join(options.dir, swSrc)
console.log(`> Service worker source path: "${swSrcPath}"`)
console.log('> Using "WorkboxPlugin.InjectManifest" plugin')
config.plugins.push(
new InjectManifest({
swDest: swDestPath,
swSrc: swSrcPath,
maximumFileSizeToCacheInBytes: 9765 * 1024, // 10Mb
})
)
}
console.log("> Progressive web app configuration complete")
return config
},
}
}
// const development = process.env.NODE_ENV !== "production"
module.exports = withWorkbox({ ...nextConfig, workbox: { swSrc: "worker.js", force: process.env.PWA_ENABLED } })
// module.exports = nextConfig