-
Notifications
You must be signed in to change notification settings - Fork 6
/
next.config.js
58 lines (52 loc) · 1.64 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
const withPWA = require("next-pwa");
// modifies Next.js's internal webpack config to add autogenerated typings for css modules
const withTypedCssModules = config => {
const cssLoaderRegex = /(?<!post)css-loader/;
const typingsForCssModulesLoader = {
loader: "@teamsupercell/typings-for-css-modules-loader",
options: {
disableLocalsExport: true,
verifyOnly: process.env.NODE_ENV === "production",
banner: `
// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY
`.trimStart(),
},
};
// looking for the webpack rules where `css-loader` is specified
const { oneOf } = config.module.rules.find(rule => Array.isArray(rule.oneOf));
const rules = oneOf.filter(rule => Array.isArray(rule.use));
rules.forEach(rule => {
const cssLoaderIndex = rule.use.findIndex(loader => cssLoaderRegex.test(loader.loader));
// no `css-loader` here -> skip
if (cssLoaderIndex === -1) {
return;
}
// webpack loaders are executed in reverse order
// we want to inject the typings loader after `css-loader`,
// but before other loaders `style-loader` or `mini-css-extract`
rule.use.splice(cssLoaderIndex, 0, { ...typingsForCssModulesLoader });
});
return config;
};
module.exports = withPWA({
reactStrictMode: true,
images: {
domains: [
"drive.google.com",
"acmucsd.s3.us-west-1.amazonaws.com",
"i.imgur.com",
"media.licdn.com",
"mojeanmac.github.io"
],
},
webpack(config) {
config = withTypedCssModules(config);
return config;
},
pwa: {
dest: "public",
register: true,
skipWaiting: true,
disable: process.env.NODE_ENV === "development",
},
});