forked from tim-soft/next-portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
124 lines (118 loc) · 4.47 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
const withOffline = require('next-offline');
const path = require('path');
const isDev = process.env.NODE_ENV === 'development';
/**
* Configure Next.js
*
* @see https://nextjs.org/docs/#custom-configuration
*/
const nextConfig = {
// Build-time variables available via `process.env` within the app
env: {
// Canonical URL for this app
APP_BASE_URL: isDev
? `http://localhost:${process.env.PORT || 3000}`
: 'https://timellenberger.com',
// Google Analytics tracking ID
GA_TRACKING_ID: 'UA-137363397-1',
},
future: {
webpack5: true,
},
// Alias the /components and /layouts folders for imports
// e.g. import xyz from 'components/xyz'
webpack(config, { webpack }) {
const newConfig = config;
newConfig.resolve.alias.components = path.join(__dirname, 'components');
newConfig.resolve.alias.layouts = path.join(__dirname, 'layouts');
newConfig.resolve.alias.data = path.join(__dirname, 'data');
newConfig.resolve.alias.hooks = path.join(__dirname, 'hooks');
// Allow proper tree shaking for react-icons lib
// https://github.com/react-icons/react-icons/issues/154#issuecomment-412774515
newConfig.resolve.extensions = ['.mjs', '.js', '.jsx', '.json'];
// Optimize react-highlight bundle
// https://react-highlight.neostack.com/docs/optimisation
newConfig.plugins.push(
new webpack.ContextReplacementPlugin(
/highlight\.js[/\\]lib[/\\]languages$/,
new RegExp(`^./(javascript)$`)
)
);
return newConfig;
},
// Now 2.0 Build Type
// https://nextjs.org/blog/next-8#serverless-nextjs
target: 'serverless',
// Add manifest to WorkBox cache
// transformManifest: manifest => ['/'].concat(manifest),
// Service Worker implemented via next-offline and powered by Workbox
// https://github.com/hanford/next-offline#next-offline-options
// https://developers.google.com/web/tools/workbox/guides/configure-workbox
workboxOpts: {
swDest: 'static/service-worker.js',
runtimeCaching: [
// Always pull images from cache if available
{
urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif|webp|ico)/,
handler: 'CacheFirst',
options: {
cacheName: 'image-cache',
cacheableResponse: {
statuses: [0, 200],
},
expiration: {
maxEntries: 200,
},
},
},
/**
* Cache Google Fonts
*
* https://developers.google.com/web/tools/workbox/
*/
// Cache the Google Fonts stylesheets with a stale while revalidate strategy.
{
urlPattern: /^https:\/\/fonts\.googleapis\.com/,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'google-fonts-stylesheets',
},
},
// Cache the Google Fonts webfont files with a cache first strategy for 1 year.
{
urlPattern: /^https:\/\/fonts\.gstatic\.com/,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-webfonts',
cacheableResponse: {
statuses: [0, 200],
},
expiration: {
maxAgeSeconds: 60 * 60 * 24 * 365,
},
},
},
// Cache all other secure content, but try to fetch from network first
{
urlPattern: /^https?.*/,
handler: 'NetworkFirst',
options: {
cacheName: 'https-calls',
networkTimeoutSeconds: 15,
expiration: {
maxEntries: 200,
maxAgeSeconds: 30 * 24 * 60 * 60, // 1 month
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
};
// Compose next-offline plugin with next config
const offlinePlugin = withOffline(nextConfig);
// https://nextjs.org/docs/#production-deployment
// Don't include Service Worker in dev
module.exports = isDev ? nextConfig : offlinePlugin;