-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
86 lines (76 loc) · 2.22 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
/* eslint-disable no-param-reassign */
const path = require('path');
const resConfig = require('./rescript.json');
const transpileModules = ['rescript'].concat(resConfig['bs-dependencies']);
// eslint-disable-next-line import/order
const withTM = require('next-transpile-modules')(transpileModules);
/**
* 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) {
return {
...modules,
exportLocalsConvention: 'dashesOnly',
mode: 'local',
};
}
const nextConfiguration = {
pageExtensions: ['jsx', 'js'],
env: {
ENV: process.env.NODE_ENV,
},
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
},
images: {
domains: ['cdn.sanity.io'],
},
webpack: (config, options) => {
config.resolve.alias['@'] = path.join(__dirname, 'src');
const oneOf = config.module.rules.find((rule) => {
return typeof rule.oneOf === 'object';
});
if (oneOf) {
// Find the module which targets *.scss|*.sass files
const moduleSassRule = oneOf.oneOf.find((rule) => {
return regexEqual(rule.test, /\.module\.(scss|sass)$/);
});
if (moduleSassRule) {
// Get the config object for css-loader plugin
const cssLoader = moduleSassRule.use.find(({ loader }) => {
return loader.includes('css-loader');
});
if (cssLoader) {
cssLoader.options = {
...cssLoader.options,
modules: cssLoaderOptions(cssLoader.options.modules),
};
}
}
}
// We need this additional rule to make sure that mjs files are
// correctly detected within our src/ folder
config.module.rules.push({
test: /\.m?js$/,
use: options.defaultLoaders.babel,
exclude: /node_modules/,
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
});
return config;
},
};
module.exports = withTM(nextConfiguration);