This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
134 lines (120 loc) · 3.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const path = require('path');
const webpack = require('webpack');
const withPlugins = require('next-compose-plugins');
const withTranspileModules = require('next-transpile-modules');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
let env;
switch (process.env.NODE_ENV) {
case 'production':
env = 'PROD';
break;
case 'staging':
env = 'STAGING';
break;
case 'development':
env = 'DEV';
break;
default:
env = 'DEV';
break;
}
const nextConfig = {
target: 'serverless',
/**
* If some of the envs are public, like a google maps key, but you still
* want to keep them secret from the repo, the following code will allow you
* to share some variables with the client, configured at compile time.
*/
env: {
ENV: env,
apiEntriesUrl:
'https://cdn.contentful.com/spaces/mivicpf5zews/environments/master/entries',
// Public token, not a secret
tokenContentful:
'102b6ce0b5beb8e64d0139b604153c92f7476229ee4d2ed5fa3608f2b72640e4',
},
};
module.exports = withPlugins(
[
[
withTranspileModules,
{
transpileModules: [],
webpack: (config, options) => {
process.env.BUNDLE_ANALYZE &&
config.plugins.push(new BundleAnalyzerPlugin());
config.plugins.push(
new SWPrecacheWebpackPlugin({
minify: true,
runtimeCaching: [
{
handler: 'networkFirst',
urlPattern: /^https?.*/,
},
],
staticFileGlobsIgnorePatterns: [/\.next\//],
})
);
// Fixes npm packages that depend on `fs` module
config.node = {
fs: 'empty',
};
config.module.rules.push({
test: /\.test.js$/,
loader: 'ignore-loader',
});
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
config.module.rules.push({
test: /\.(eot|woff|woff2)$/,
loader: 'ignore-loader',
});
/* support absolute path */
config.resolve.alias['~'] = __dirname;
const usePolyfill = false;
if (usePolyfill) {
// https://stackoverflow.com/a/53311389/815507
// https://github.com/zeit/next.js/issues/2060#issuecomment-385199026
const originalEntry = config.entry;
config.entry = async () => {
const entries = await originalEntry();
if (
entries['main.js'] &&
!entries['main.js'].includes('./client/polyfills.js')
) {
entries['main.js'].unshift('./client/polyfills.js');
}
return entries;
};
}
return config;
},
},
],
//[withSass],
[nextConfig],
process.env.BUNDLE_ANALYZE && [
// https://github.com/zeit/next-plugins/tree/master/packages/next-bundle-analyzer
withBundleAnalyzer,
{
analyzeServer:
true || ['server', 'both'].includes(process.env.BUNDLE_ANALYZE),
analyzeBrowser:
true || ['browser', 'both'].includes(process.env.BUNDLE_ANALYZE),
bundleAnalyzerConfig: {
server: {
analyzerMode: 'static',
reportFilename: './server.html',
},
browser: {
analyzerMode: 'static',
reportFilename: './client.html',
},
},
},
],
].filter(Boolean)
);