-
Notifications
You must be signed in to change notification settings - Fork 4
/
next.config.js
44 lines (34 loc) · 1.15 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
const path = require("path");
const withPlugins = require("next-compose-plugins");
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true"
});
require("./server/env");
const serverPath = path.join(process.cwd(), "server");
const nextConfiguration = {
// can't use standalone output as we have a custom server
//output: "standalone",
env: {},
webpack(config, options) {
if (!config.externals) {
config.externals = [];
}
config.externals.push(async ({ context, request, getResolve }) => {
const resolve = getResolve();
try {
const resolved = await resolve(context, request);
// Modules that are in the server directory should not be loaded
// more than once and thus shouldn't be optimized
if (resolved && resolved.indexOf(serverPath) === 0) {
return `commonjs ${resolved}`;
}
} catch (e) {
// Nothing to do here, it's quite common to not always resolve
}
return undefined;
});
return config;
}
};
const plugins = [withBundleAnalyzer];
module.exports = withPlugins([...plugins], nextConfiguration);