-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathnext.config.js
123 lines (102 loc) · 2.86 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
const path = require('path')
const { withSentryConfig } = require('@sentry/nextjs')
const nextTranspileModules = require('next-transpile-modules')
const modulesToTranspile = [
'@toptal/picasso',
'@toptal/picasso-provider',
'@toptal/utilities-ui-library'
]
const sentryWebpackPluginOptions = {
ignore: ['node_modules'],
include: '.next',
silent: process.env.NODE_ENV !== 'production',
configFile: 'sentry.properties',
dryRun: !process.env.NEXT_PUBLIC_SENTRY_DSN
}
if (process.env.NODE_ENV === 'development') {
const mock = require('mock-require')
// `mock-require` package needs it :(
modulesToTranspile.push('date-fns')
const QUILL_MOCK_PATH = path.join(__dirname, '/lib/patched-quill')
mock('quill', QUILL_MOCK_PATH)
mock('quill-delta', QUILL_MOCK_PATH)
mock('quill-paste-smart', QUILL_MOCK_PATH)
}
const withTM = nextTranspileModules(modulesToTranspile)
const transformClassNamesToCamelCase = config => {
const rules = config.module.rules
.find(rule => typeof rule.oneOf === 'object')
.oneOf.filter(rule => Array.isArray(rule.use))
rules.forEach(rule => {
rule.use.forEach(moduleLoader => {
if (
typeof moduleLoader === 'object' &&
moduleLoader.loader.includes('css-loader') &&
typeof moduleLoader.options.modules === 'object'
) {
moduleLoader.options = {
...moduleLoader.options,
modules: {
...moduleLoader.options.modules,
exportLocalsConvention: 'camelCase'
}
}
}
})
})
}
const noindexEnabled =
typeof process.env.NEXT_PUBLIC_SEARCH_INDEXING === 'undefined'
const buildHeaders = async () => {
const headers = []
if (noindexEnabled) {
headers.push({
source: '/:path*',
headers: [
{
key: 'X-Robots-Tag',
value: 'noindex, nofollow, nosnippet, noarchive'
}
]
})
}
return headers
}
const nextConfig = {
swcMinify: true,
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
sassOptions: {
includePaths: [path.join(__dirname, 'styles')], // this is to use `@import 'base.scss';` in scss files
additionalData: `$basePath: "${process.env.NEXT_PUBLIC_BASE_PATH || ''}";`
},
sentry: {
hideSourceMaps: true
},
env: {
noindexEnabled
},
webpack: config => {
transformClassNamesToCamelCase(config)
return config
},
redirects: async () => {
return [
{
source: '/for/:key',
destination: '/:key',
permanent: true
},
{
source: '/%',
destination: '/percent',
permanent: true
}
]
},
headers: buildHeaders
}
const moduleExports = () => {
const plugins = [withTM] // add plugins here: [withTM, withSomethingElse]
return plugins.reduce((config, next) => next(config), nextConfig)
}
module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions)