-
Notifications
You must be signed in to change notification settings - Fork 7
/
next.config.js
136 lines (127 loc) · 3.66 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
135
136
const withPWA = require('next-pwa');
const withPlugins = require('next-compose-plugins');
const withCamelCaseCSSModules = require('./plugins/next-css-modules');
const { isDevProcess, isProdProcess } = require('@powerfulyang/utils');
const runtimeCaching = require('next-pwa/cache');
const { withSentryConfig } = require('@sentry/nextjs');
/**
* @type {string}
*/
const API_ENV = process.env.API_ENV;
const sentryWebpackPluginOptions = {
// Additional config options for the Sentry Webpack plugin. Keep in mind that
// the following options are set automatically, and overriding them is not
// recommended:
// release, url, org, project, authToken, configFile, stripPrefix,
// urlPrefix, include, ignore
silent: false, // Suppresses all logs
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
};
const excludeCacheNames = ['next-data', 'apis'];
const defaultCacheRule = runtimeCaching.filter((x) => {
return !excludeCacheNames.includes(x.options.cacheName);
});
if (API_ENV === 'prod') {
process.env.CLIENT_BASE_URL = 'https://api.powerfulyang.com/api';
process.env.SERVER_BASE_URL = 'https://api.powerfulyang.com/api';
}
if (API_ENV === 'qa') {
process.env.CLIENT_BASE_URL = 'https://qa.powerfulyang.com/api';
process.env.SERVER_BASE_URL = 'https://qa.powerfulyang.com/api';
}
if (API_ENV === 'local') {
process.env.CLIENT_BASE_URL = '/api';
process.env.SERVER_BASE_URL = 'http://localhost:3001/api';
}
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
/**
* @type {import('next').NextConfig}
*/
const config = {
rewrites() {
return [
{
source: '/',
destination: '/post',
},
{
source: '/post/thumbnail/:id',
destination: '/post',
},
{
source: '/post/publish',
destination: '/post/publish/0',
},
];
},
pwa: {
dest: 'public',
disable: isDevProcess,
runtimeCaching: [
...defaultCacheRule,
{
urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
handler: 'NetworkFirst',
options: {
cacheName: 'next-data',
expiration: {
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
networkTimeoutSeconds: 1, // fall back to cache if api does not response within 1 seconds
},
},
{
urlPattern: ({ url }) => {
const isSameOrigin = self.origin === url.origin;
const pathname = url.pathname;
return isSameOrigin && pathname.startsWith('/api/');
},
handler: 'NetworkFirst',
method: 'GET',
options: {
cacheName: 'apis',
expiration: {
maxEntries: 16,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
networkTimeoutSeconds: 1, // fall back to cache if api does not response within 1 seconds
},
},
],
},
experimental: {
esmExternals: true,
},
env: {
CLIENT_BASE_URL: process.env.CLIENT_BASE_URL,
NEXT_PUBLIC_SENTRY_DSN:
'https://f4e15b44f3674255b6eed1cb673c0dcb@o417744.ingest.sentry.io/6340260',
},
eslint: {
ignoreDuringBuilds: true, //不用自带的
},
reactStrictMode: true,
typescript: {
ignoreBuildErrors: true,
},
sentry: {
disableServerWebpackPlugin: isDevProcess,
disableClientWebpackPlugin: isDevProcess,
},
productionBrowserSourceMaps: isProdProcess,
optimizeFonts: false,
swcMinify: false,
};
module.exports = withPlugins(
[
withCamelCaseCSSModules,
withPWA,
withBundleAnalyzer,
[withSentryConfig, sentryWebpackPluginOptions],
],
config,
);