-
Notifications
You must be signed in to change notification settings - Fork 2
/
next.config.js
80 lines (77 loc) · 2.71 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
// See: https://github.com/vercel/next.js/issues/8106
const withSourceMaps = require("@zeit/next-source-maps")();
const withLess = require("@zeit/next-less");
const lessToJS = require("less-vars-to-js");
const fs = require("fs");
const path = require("path");
// See: https://flaviocopes.com/nextjs-analyze-app-bundle/
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true",
});
const themeVariables = lessToJS(fs.readFileSync(path.resolve(__dirname, "./components/antd-custom.less"), "utf8"));
module.exports = withBundleAnalyzer(
withLess(
withSourceMaps({
serverRuntimeConfig: {
PROJECT_ROOT: __dirname,
},
// Powers less variables.
// See: https://github.com/vercel/next.js/issues/9830#issuecomment-636509363
lessLoaderOptions: {
javascriptEnabled: true,
modifyVars: themeVariables, // make your antd custom effective
},
async rewrites() {
// Part of powering client-side routing.
// See: https://colinhacks.com/essays/building-a-spa-with-nextjs
return [
// Rewrite everything else to use `pages/index`
{
source: "/api/:path*",
destination: "/api/:path*",
},
{
source: "/:path*",
destination: "/",
},
];
},
webpack: (config, options) => {
// Fixes npm packages that depend on `fs` module
config.node = {
fs: "empty",
};
// Ant Design Configs
// See: https://github.com/vercel/next.js/issues/9830#issuecomment-636509363
if (options.isServer) {
const antStylesRegex = /antd\/.*?\/style.*?/;
const origExternals = [...config.externals];
config.externals = [
(context, request, callback) => {
if (request.match(antStylesRegex)) return callback();
if (typeof origExternals[0] === "function") {
origExternals[0](context, request, callback);
} else {
callback();
}
},
...(typeof origExternals[0] === "function" ? [] : origExternals),
];
config.module.rules.unshift({
test: antStylesRegex,
use: "null-loader",
});
} else {
/* aliases ant icon imports to user-defined icons folder */
config.resolve.alias = {
...config.resolve.alias,
"@ant-design/icons/lib/dist$": path.resolve(`./components/icons.ts`),
};
/* strips out moment locales */
// config.plugins.push(new IgnorePlugin(/^\.\/locale$/, /moment$/));
}
return config;
},
})
)
);