-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnext.config.js
139 lines (120 loc) · 3.39 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
137
138
139
const webpack = (config, options) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
/**
* Fix locales issue
* https://github.com/moment/moment/issues/2517#issuecomment-620674018
*/
config.plugins.push(
new MomentLocalesPlugin({
localesToKeep: ['ru', 'en'],
})
)
config.module.rules.push({
test: /\.pdf/,
use: [
options.defaultLoaders.babel,
{
loader: 'file-loader',
options: {
limit: 1000,
name: '[name]_[hash].[ext]',
publicPath: `/_next/static/pdf`,
outputPath: 'static/pdf',
},
},
],
})
// https://github.com/vercel/next.js/issues/11164#issuecomment-602204795
config.module.rules.push({
// test: /\.(png|jpe?g|gif)$/i,
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
// loader: 'url-loader',
// issuer: {
// // nextjs already handles url() in css/sass/scss files
// test: /\.\w+(?<!(s?c|sa)ss)$/i,
// },
use: [
{
loader: 'url-loader',
options: {
context: 'src',
name() {
if (process.env.NODE_ENV === 'development') {
return '[path][name].[ext]'
}
return '[contenthash].[ext]'
},
publicPath: `/_next/static/media`,
outputPath: 'static/media',
limit: 1000,
},
},
],
})
// Object.assign(config, {
// // https://nextjs.org/docs/api-reference/next.config.js/disabling-etag-generation
// generateEtags: false,
// });
return config
// Important: return the modified config
// return {
// ...config,
// // https://nextjs.org/docs/api-reference/next.config.js/disabling-etag-generation
// generateEtags: false,
// }
}
module.exports = (phase, defaultConfig) => {
if (phase !== 'phase-production-server') {
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
const withPWA = require('next-pwa')
let config = withBundleAnalyzer(
withPWA({
pwa: {
dest: `.next/public`,
// TODO Пока не работает как хотелось бы
// fallbacks: {
// // image: '/static/images/fallback.png',
// // document: '/offline', // if you want to fallback to a custom page other than /_offline
// // font: '/static/font/fallback.woff2',
// // audio: ...,
// // video: ...,
// },
disable:
process.env.PWA !== 'true' ||
process.env.NODE_ENV === 'development',
},
webpack,
// https://github.com/shadowwalker/next-pwa/issues/198#issuecomment-817205700
future: {
webpack5: true,
},
})
)
/**
* Github pages
*/
if (
process.env.GITHUB_REPOSITORY &&
['phase-production-build', 'phase-export'].includes(phase)
) {
const repositoryName = process.env.GITHUB_REPOSITORY.split('/')[1]
config = {
...config,
assetPrefix: `/${repositoryName}/`,
basePath: `/${repositoryName}`,
}
}
return config
}
// else
// return defaultConfig
return {
...defaultConfig,
webpack,
generateEtags: false,
}
}