This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
next.config.js
100 lines (97 loc) · 2.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
const routes = require('./routes')
const path = require('path')
const { resolve } = require('./webpack.config.js')
const withPlugins = require('next-compose-plugins')
const withMDX = require('@zeit/next-mdx')({
extension: /\.mdx?$/
})
const withImages = require('next-optimized-images')
const withBundleAnalyzer = require('./config/bundle-analyzer')
/**
* Next/Webpack config
*/
const config = {
async exportPathMap() {
return routes()
},
pageExtensions: ['js', 'jsx', 'mdx'],
webpack(config, options) {
config.resolve = {
...config.resolve,
...resolve,
alias: {
...config.resolve.alias,
...resolve.alias
}
}
config.module.rules.push({
test: /\.(woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000',
include: [path.resolve(__dirname, 'assets/fonts')]
})
config.node = {
...config.node,
fs: 'empty',
net: 'empty',
tls: 'empty'
}
config.module.rules.push({
test: /\.(jpe?g|png)$/i,
loader: 'responsive-loader',
options: {
quality: 60,
adapter: require('responsive-loader/sharp'),
placeholder: true,
placeholderSize: 80,
name: 'static/images/[name]-[hash]-[width].[ext]'
}
})
if (config.mode === 'production' && config.name === 'client') {
config.optimization.splitChunks.cacheGroups.commons.minChunks = 2;
}
return config
}
}
const plugins = [
[
withImages,
{
handleImages: ['svg', 'webp', 'gif'],
inlineImageLimit: -1,
imagesFolder: 'images',
imagesName: '[name]-[hash].[ext]',
optimizeImagesInDev: false,
url: true,
mozjpeg: false,
optipng: false,
pngquant: false,
gifsicle: {
interlaced: true,
optimizationLevel: 3
},
webp: {
preset: 'default',
quality: 65
}
}
],
[
withBundleAnalyzer,
{
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'
}
}
}
],
withMDX
]
module.exports = withPlugins([...plugins], config)