forked from game-ci/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
100 lines (88 loc) · 2.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
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
/* eslint-disable unicorn/no-array-reduce,no-param-reassign,@typescript-eslint/no-shadow */
import { SearchIndex } from './tools/search/search-index';
const withBundleAnalyzer = require('@next/bundle-analyzer');
const withCSS = require('@zeit/next-css');
const withLess = require('@zeit/next-less');
const withSass = require('@zeit/next-sass');
const lessNextConfig = {
lessLoaderOptions: {
javascriptEnabled: true,
},
webpack: (config, options) => {
if (options.isServer) {
const antStylesPattern = /antd\/.*?\/style.*?/;
const originalExternals = [...config.externals];
config.externals = [
(context, request, callback) => {
if (antStylesPattern.test(request) || typeof originalExternals[0] !== 'function') {
callback();
} else {
originalExternals[0](context, request, callback);
}
},
...(typeof originalExternals[0] === 'function' ? [] : originalExternals),
];
config.module.rules.unshift({
test: antStylesPattern,
use: 'null-loader',
});
}
return config;
},
};
const sassNextConfig = {
cssModules: true,
};
const compose = (plugins) => ({
target: 'serverless',
// Interpreted at build-time
publicRuntimeConfig: {
SEARCH_INDEX: SearchIndex.getForCurrentEnvironment(),
},
webpack: (config, options) => {
config.module.rules.push(
{
test: /\.md$/,
use: 'raw-loader',
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
);
return plugins.reduce((config, plugin) => {
if (Array.isArray(plugin)) {
const [pluginFunction, ...pluginArguments] = plugin;
plugin = pluginFunction(...pluginArguments);
}
if (plugin instanceof Function) {
plugin = plugin();
}
if (plugin && plugin.webpack instanceof Function) {
return plugin.webpack(config, options);
}
return config;
}, config);
},
webpackDevMiddleware(config) {
return plugins.reduce((config, plugin) => {
if (Array.isArray(plugin)) {
const [pluginFunction, ...pluginArguments] = plugin;
plugin = pluginFunction(...pluginArguments);
}
if (plugin instanceof Function) {
plugin = plugin();
}
if (plugin && plugin.webpackDevMiddleware instanceof Function) {
return plugin.webpackDevMiddleware(config);
}
return config;
}, config);
},
});
module.exports = compose([
[withBundleAnalyzer, { enabled: process.env.ANALYZE === 'true' }],
[withCSS],
[withLess, lessNextConfig],
[withSass, sassNextConfig],
]);