-
Notifications
You must be signed in to change notification settings - Fork 12
/
next.config.js
131 lines (125 loc) · 3.26 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const path = require("path")
const { withNextSidebuild, NextSidebuild } = require("@hazae41/next-sidebuild")
const withMDX = require("@next/mdx")()
module.exports = withMDX(withNextSidebuild({
output: "export",
reactStrictMode: false, // TODO
pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"],
env: {
VERSION: process.env.npm_package_version
},
generateBuildId() {
return "immutable"
},
webpack: (config) => {
config.optimization.minimize = true
return config
},
sidebuilds: function* (wpconfig) {
yield compileServiceWorker(wpconfig)
yield compileContentScript(wpconfig)
yield compileInjectedScript(wpconfig)
yield compileOffscreen(wpconfig)
},
async headers() {
return [
{
source: "/:path*",
headers: [
{
key: "Allow-CSP-From",
value: "*"
},
{
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
}
]
}
]
}
}))
async function compileServiceWorker(wpconfig) {
await NextSidebuild.compile({
name: "service_worker",
devtool: false,
target: "webworker",
mode: wpconfig.mode,
resolve: wpconfig.resolve,
resolveLoader: wpconfig.resolveLoader,
module: wpconfig.module,
plugins: wpconfig.plugins,
entry: "./src/mods/background/service_worker/index.ts",
output: {
path: path.join(process.cwd(), ".webpack"),
filename: "./service_worker.js"
},
optimization: {
minimize: true,
minimizer: wpconfig.optimization.minimizer
}
})
}
async function compileContentScript(wpconfig) {
await NextSidebuild.compile({
name: "content_script",
devtool: false,
target: "webworker",
mode: wpconfig.mode,
resolve: wpconfig.resolve,
resolveLoader: wpconfig.resolveLoader,
module: wpconfig.module,
plugins: wpconfig.plugins,
entry: "./src/mods/background/content_script/index.ts",
output: {
path: path.join(process.cwd(), ".webpack"),
filename: "./content_script.js"
},
optimization: {
minimize: true,
minimizer: wpconfig.optimization.minimizer
}
})
}
async function compileInjectedScript(wpconfig) {
await NextSidebuild.compile({
name: "injected_script",
devtool: false,
target: "web",
mode: wpconfig.mode,
resolve: wpconfig.resolve,
resolveLoader: wpconfig.resolveLoader,
module: wpconfig.module,
plugins: wpconfig.plugins,
entry: "./src/mods/background/injected_script/index.ts",
output: {
path: path.join(process.cwd(), ".webpack"),
filename: "./injected_script.js"
},
optimization: {
minimize: true,
minimizer: wpconfig.optimization.minimizer
}
})
}
async function compileOffscreen(wpconfig) {
await NextSidebuild.compile({
name: "offscreen",
devtool: false,
target: "web",
mode: wpconfig.mode,
resolve: wpconfig.resolve,
resolveLoader: wpconfig.resolveLoader,
module: wpconfig.module,
plugins: wpconfig.plugins,
entry: "./src/mods/background/offscreen/index.ts",
output: {
path: path.join(process.cwd(), ".webpack"),
filename: "./offscreen.js"
},
optimization: {
minimize: true,
minimizer: wpconfig.optimization.minimizer
}
})
}