-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
63 lines (57 loc) · 1.6 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
require('dotenv').config()
/**
* Stolen from https://stackoverflow.com/questions/10776600/testing-for-equality-of-regular-expressions
*/
const regexEqual = (x, y) => {
return (
x instanceof RegExp &&
y instanceof RegExp &&
x.source === y.source &&
x.global === y.global &&
x.ignoreCase === y.ignoreCase &&
x.multiline === y.multiline
)
}
// Overrides for css-loader plugin
function cssLoaderOptions(modules) {
// const { getLocalIdent, ...others } = modules // Need to delete getLocalIdent else localIdentName doesn't work
return {
...modules,
// ...others,
localIdentName: '[hash:base64:6]',
exportLocalsConvention: 'camelCaseOnly',
mode: 'local',
}
}
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: false,
env: {
NEXT_EXAMPLE_CMS_DATOCMS_API_TOKEN:
process.env.NEXT_EXAMPLE_CMS_DATOCMS_API_TOKEN,
},
webpack: config => {
const oneOf = config.module.rules.find(
rule => typeof rule.oneOf === 'object'
)
if (oneOf) {
// Find the module which targets *.scss|*.sass files
const moduleSassRule = oneOf.oneOf.find(rule =>
regexEqual(rule.test, /\.module\.(scss|sass)$/)
)
if (moduleSassRule) {
// Get the config object for css-loader plugin
const cssLoader = moduleSassRule.use.find(({ loader }) =>
loader.includes('css-loader')
)
if (cssLoader) {
cssLoader.options = {
...cssLoader.options,
modules: cssLoaderOptions(cssLoader.options.modules),
}
}
}
}
return config
},
}