-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
106 lines (98 loc) · 3.51 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
const { join } = require('path')
const withCSS = require('@zeit/next-css'),
withStylus = require('@zeit/next-stylus'),
withOffline = require('next-offline'),
withAnalyze = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
}),
withPlugins = require('next-compose-plugins')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'),
TerserPlugin = require('terser-webpack-plugin')
module.exports = withPlugins(
[
[withAnalyze],
[withCSS],
[
withStylus,
{
loaders: [
{
test: /\.styl$/,
loader:
'css-loader!stylus-loader?paths=node_modules/bootstrap-stylus/stylus/',
},
],
},
],
[
withOffline,
{
dontAutoRegisterSw: true,
workboxOpts: {
swDest: 'static/service-worker.js',
runtimeCaching: [
{
urlPattern: /.js$|.ttf$|.otf$|.css$|.svg$|.jpg$|.png$/,
handler: 'CacheFirst',
},
],
},
},
],
],
{
target: 'serverless',
experimental: {
modern: true,
polyfillsOptimization: true,
},
webpack(config, options) {
const splitChunks =
config.optimization && config.optimization.splitChunks
if (splitChunks) {
const cacheGroups = splitChunks.cacheGroups
const preactModules = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/
if (cacheGroups.framework) {
cacheGroups.preact = Object.assign(
{},
cacheGroups.framework,
{
test: preactModules,
}
)
cacheGroups.commons.name = 'framework'
} else
cacheGroups.preact = {
name: 'commons',
chunks: 'all',
test: preactModules,
}
}
config.optimization.minimize = true
config.optimization.minimizer.push(new OptimizeCSSAssetsPlugin({}))
config.optimization.minimizer.push(
new TerserPlugin({
terserOptions: {
mangle: true, // Note `mangle.properties` is `false` by default.
},
})
)
config.resolve.alias = {
...config.resolve.alias,
react: 'preact/compat',
'react-dom': 'preact/compat',
'react-render-to-string': 'preact-render-to-stirng',
pages: join(__dirname, 'pages'),
'~': join(__dirname, 'public'),
styles: join(__dirname, 'public/styles'),
fonts: join(__dirname, 'public/fonts'),
components: join(__dirname, 'components'),
libs: join(__dirname, 'libs'),
pageTypes: join(__dirname, 'pageTypes'),
stores: join(__dirname, 'stores'),
layouts: join(__dirname, 'layouts'),
}
return config
},
}
)