-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
next.config.js
91 lines (82 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
81
82
83
84
85
86
87
88
89
90
91
const path = require('path');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
module.exports = () => {
const isProduction = process.env.VERCEL_GIT_COMMIT_REF === 'master';
const productionEnv = {
REACT_APP_API_HOST: process.env.API_HOST,
GITHUB_URL: process.env.GITHUB_URL,
GITHUB_TOKEN: process.env.GITHUB_TOKEN,
HUBSPOT_LIST_ID: process.env.HUBSPOT_LIST_ID,
HUBSPOT_APIKEY: process.env.HUBSPOT_APIKEY,
SLACK_HOOK_URL: process.env.SLACK_HOOK_URL,
};
const stageEnv = {
REACT_APP_API_HOST: process.env.STAGE_API_HOST,
GITHUB_URL: process.env.STAGE_GITHUB_URL,
GITHUB_TOKEN: process.env.STAGE_GITHUB_TOKEN,
HUBSPOT_LIST_ID: process.env.STAGE_HUBSPOT_LIST_ID,
HUBSPOT_APIKEY: process.env.STAGE_HUBSPOT_APIKEY,
SLACK_HOOK_URL: process.env.STAGE_SLACK_HOOK_URL,
};
// env vars can be found on vercel.com
const env = isProduction ? productionEnv : stageEnv;
// for tests
if (process.env.REACT_APP_API_HOST) {
env.REACT_APP_API_HOST = process.env.REACT_APP_API_HOST;
}
const nextConfig = {
env,
webpack: (baseConfig, { isServer, dev, webpack }) => {
const config = { ...baseConfig };
// add custom webpack config only for the client side in production
if (!isServer && !dev) {
// ignore momentjs locales
config.plugins.push(
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
})
);
// lodash is referenced by multiple libraries,
// this makes sure we only inlcude it once
config.resolve.alias = {
...config.resolve.alias,
lodash: path.resolve(__dirname, 'node_modules/lodash'),
};
config.optimization.splitChunks = {
chunks: 'all',
cacheGroups: {
default: false,
vendors: false,
commons: {
name: 'commons',
chunks: 'all',
minChunks: 3,
},
charts: {
name: 'charts',
chunks: 'all',
test: /[\\/]node_modules[\\/](recharts|d3.*)[\\/]/,
enforce: true,
priority: 10,
},
// Only create one CSS file
styles: {
name: `styles`,
// This should cover all our types of CSS.
test: /\.(css|scss|sass)$/,
chunks: `all`,
enforce: true,
// this rule trumps all other rules because of the priority.
priority: 10,
},
},
};
}
return config;
},
};
return withBundleAnalyzer(nextConfig);
};