forked from styled-components/styled-components-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
67 lines (58 loc) · 1.76 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
const path = require('path')
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
webpack: function (config, { dev }) {
if (dev) {
return config
}
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
// For all options see https://github.com/th0r/webpack-bundle-analyzer#as-plugin
generateStatsFile: true,
// Will be available at `.next/stats.json`
statsFilename: 'stats.json'
})
)
const oldEntry = config.entry
config.entry = () => oldEntry()
.then(entry => {
entry['main.js'].push(
path.resolve('./utils/offline.js'),
path.resolve('./utils/track.js')
)
entry.commons = ['./utils/prismTemplateString.js']
return entry
})
config.resolve.alias = config.resolve.alias || {}
config.plugins.push(
new SWPrecacheWebpackPlugin({
filename: 'sw.js',
minify: true,
staticFileGlobsIgnorePatterns: [
/\.next\//,
/sc-micro-analytics\.now\.sh/
],
staticFileGlobs: [
'static/**/*' // Precache all static files by default
],
forceDelete: true,
runtimeCaching: [
// Example with different handlers
{
handler: 'fastest',
urlPattern: /[.](png|jpg|css)/
},
{
handler: 'networkFirst',
urlPattern: /^http.*/ //cache all files
}
]
})
)
config.resolve.alias['react'] = 'preact-compat/dist/preact-compat'
config.resolve.alias['react-dom'] = 'preact-compat/dist/preact-compat'
return config
}
}