-
Notifications
You must be signed in to change notification settings - Fork 1
/
next.config.js
116 lines (107 loc) · 3.47 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
/* eslint-disable max-statements */
/**
* @todo might be able to put more of these in build-time only
* @see https://github.com/zeit/next.js/issues/876
* @see https://github.com/vercel/next.js/discussions/13810
*/
const withOffline = require('next-offline')
const { env, envWithoutNodeEnv } = require('./env')
/**
* @description Make sure any symlinks in the project folder are resolved:
* @see https://github.com/facebookincubator/create-react-app/issues/637
*/
const { resolve, join } = require('path')
const { realpathSync } = require('fs')
const appDirectory = realpathSync(process.cwd())
const resolveApp = relativePath => resolve(appDirectory, relativePath)
/**
* @see https://zeit.co/examples/nextjs/
* @see https://zeit.co/docs/v2/deployments/ignoring-source-paths
* @see https://github.com/hanford/next-offline/tree/master/examples/now2
*
* @see https://nextjs.org/docs#build-time-configuration
*/
const nextConfig = {
images: {
domains: ['noccumpr-cdn.sirv.com', 'jameswiens.dev'],
imageSizes: [
400, 600, 581, 800, 1000, 1200, 1400, 1600, 2000, 2477, 3000, 4024, 5000,
],
},
amp: 'hybrid',
env: envWithoutNodeEnv,
target:
process.env.DISABLE_SERVERLESS !== undefined ? 'server' : 'serverless',
webpack(config, options) {
if (process.env.IS_DOCKER === undefined) {
const { EnvironmentPlugin } = require('webpack')
config.plugins.push(new EnvironmentPlugin(env))
}
if (process.env.NODE_ENV === 'production') {
console.debug('[next] in production mode, not type checking')
config.optimization = {
...config.optimization,
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
sideEffects: true,
usedExports: true,
providedExports: true,
concatenateModules: true,
nodeEnv: 'production',
}
return config
} else if (options.isServer) {
console.debug('[next] not type checking server')
return config
} else {
console.debug('[next] in development mode, type checking')
}
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const plugin = new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: require.resolve('./tsconfig.dev.json'),
diagnosticOptions: {
syntactic: true,
semantic: true,
declaration: false,
global: false,
},
},
})
config.plugins.push(plugin)
return config
},
/**
* @todo next-offline typings
* @todo other config
* @see https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.injectManifest
*/
workboxOpts: {
swDest: 'static/service-worker.js',
},
}
const workboxConfig = withOffline(nextConfig)
function withBuildTimeDeps() {
const withBundleAnalyzer = require('@next/bundle-analyzer')
return withBundleAnalyzer({
...workboxConfig,
analyzeServer: ['server', 'both'].includes(process.env.BUNDLE_ANALYZE),
analyzeBrowser: ['browser', 'both'].includes(process.env.BUNDLE_ANALYZE),
bundleAnalyzerConfig: {
server: {
analyzerMode: 'static',
reportFilename: '../../bundles/server.html',
},
browser: {
analyzerMode: 'static',
reportFilename: '../bundles/client.html',
},
},
})
}
module.exports =
process.env.IS_DOCKER === undefined &&
process.env.SHOULD_ANALYZE_BUNDLE !== undefined
? withBuildTimeDeps()
: workboxConfig