-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
next.config.js
134 lines (122 loc) · 4.04 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
// Serve images in WebP where available & at reduced size when possible.
const withOptimizedImages = require('next-optimized-images')
// Service Worker for Progressive Web App (PWA) standards
const withOffline = require('next-offline')
// .env Environment variables
require("dotenv").config();
const webpack = require("webpack");
// Bundle Analyzer
const withBundleAnalyzer = require("@zeit/next-bundle-analyzer")
// .MDX support
const images = require('remark-images')
const emoji = require('remark-emoji')
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
options: {
mdPlugins: [images, emoji]
}
})
// .CSS support
const withCss = require('@zeit/next-css')
// .LESS support
/* eslint-disable */
const withLess = require('@zeit/next-less')
const lessToJS = require('less-vars-to-js')
const fs = require('fs')
const path = require('path')
// Where your antd-custom.less file lives
const themeVariables = lessToJS(fs.readFileSync(path.resolve(__dirname, './assets/antd-custom.less'), 'utf8'))
module.exports = withBundleAnalyzer(withOffline(withOptimizedImages(withMDX(withCss(withLess({
// Now by ZEIT deployment target
target: 'serverless',
// Service Worker for Progressive Web App (PWA) standards
transformManifest: manifest => ['/'].concat(manifest), // add the homepage to the cache
// Trying to set NODE_ENV=production when running yarn dev causes a build-time error so we
// turn on the SW in dev mode so that we can actually test it
generateInDevMode: true,
workboxOpts: {
swDest: 'static/service-worker.js',
runtimeCaching: [
{
urlPattern: /^https?.*/,
handler: 'NetworkFirst',
options: {
cacheName: 'https-calls',
networkTimeoutSeconds: 15,
expiration: {
maxEntries: 150,
maxAgeSeconds: 30 * 24 * 60 * 60, // 1 month
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
// Deliver images in the smallest size (in increments of 200).
sizes: [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000],
// Webpack Bundle Analyzer
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'
}
},
// Markdown in JSX filetype support
pageExtensions: ['mdx', 'md', 'jsx', 'js'],
// Locally scored CSS modules
// cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]",
},
// custom webpack config for Ant Design Less
lessLoaderOptions: {
javascriptEnabled: true,
modifyVars: themeVariables, // make your antd custom effective
},
webpack: (config, { isServer }) => {
if (isServer) {
const antStyles = /antd\/.*?\/style.*?/
const origExternals = [...config.externals]
config.externals = [
(context, request, callback) => {
if (request.match(antStyles)) return callback()
if (typeof origExternals[0] === 'function') {
origExternals[0](context, request, callback)
} else {
callback()
}
},
...(typeof origExternals[0] === 'function' ? [] : origExternals),
]
config.module.rules.unshift({
test: antStyles,
use: 'null-loader',
})
}
// Fixes npm packages that depend on `fs` module
config.node = {
fs: 'empty'
}
/**
* Returns environment variables as an object
*/
const env = Object.keys(process.env).reduce((acc, curr) => {
acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]);
return acc;
}, {});
/** Allows you to create global constants which can be configured
* at compile time, which in our case is our environment variables
*/
config.plugins.push(new webpack.DefinePlugin(env));
return config
},
}))))))