Skip to content

Commit c8d6982

Browse files
committed
fix(build): get the thing to work maybe?
1 parent c89bd67 commit c8d6982

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

website/next.config.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11

2-
const withTypedCssModules = (nextConfig = {}) => ({
3-
...nextConfig,
4-
webpack (config) {
5-
const cssLoaderRegex = /(?<!post)css-loader/;
6-
const typingsForCssModulesLoader = {
7-
loader: "@teamsupercell/typings-for-css-modules-loader",
8-
options: {
9-
disableLocalsExport: true,
10-
verifyOnly: process.env.NODE_ENV === "production",
11-
banner: `// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY\n`,
12-
},
13-
};
2+
const withTypedCssModules = (webpackConfig) => {
3+
const cssLoaderRegex = /(?<!post)css-loader/;
4+
const typingsForCssModulesLoader = {
5+
loader: "@teamsupercell/typings-for-css-modules-loader",
6+
options: {
7+
disableLocalsExport: true,
8+
verifyOnly: process.env.NODE_ENV === "production",
9+
banner: `// AUTOGENERATED FILE -- DO NOT EDIT DIRECTLY\n`,
10+
},
11+
};
1412

15-
// looking for the webpack rules where `css-loader` is specified
16-
const { oneOf } = config.module.rules.find((rule) => Array.isArray(rule.oneOf));
17-
const rules = oneOf.filter((rule) => Array.isArray(rule.use));
13+
// looking for the webpack rules where `css-loader` is specified
14+
const { oneOf } = webpackConfig.module.rules.find((rule) => Array.isArray(rule.oneOf));
15+
const rules = oneOf.filter((rule) => Array.isArray(rule.use));
1816

19-
rules.forEach((rule) => {
20-
const cssLoaderIndex = rule.use.findIndex((loader) => cssLoaderRegex.test(loader.loader));
21-
// no `css-loader` here -> skip
22-
if (cssLoaderIndex === -1) { return; }
23-
// webpack loaders are executed in reverse order
24-
// we want to inject the typings loader after `css-loader`,
25-
// but before other loaders `style-loader` or `mini-css-extract`
26-
rule.use.splice(cssLoaderIndex, 0, { ...typingsForCssModulesLoader });
27-
})
17+
rules.forEach((rule) => {
18+
const cssLoaderIndex = rule.use.findIndex((loader) => cssLoaderRegex.test(loader.loader));
19+
// no `css-loader` here -> skip
20+
if (cssLoaderIndex === -1) { return; }
21+
// webpack loaders are executed in reverse order
22+
// we want to inject the typings loader after `css-loader`,
23+
// but before other loaders `style-loader` or `mini-css-extract`
24+
rule.use.splice(cssLoaderIndex, 0, { ...typingsForCssModulesLoader });
25+
})
2826

29-
return config;
30-
}
31-
})
27+
return webpackConfig
28+
}
29+
3230

3331
/** @type {import('next').NextConfig} */
34-
module.exports = withTypedCssModules({
32+
module.exports = {
3533
reactStrictMode: true,
36-
})
34+
webpack (config) {
35+
config = withTypedCssModules(config)
36+
return config
37+
}
38+
}

0 commit comments

Comments
 (0)