This repository was archived by the owner on Aug 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnext.config.js
100 lines (93 loc) · 2.78 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
require("dotenv").config();
const child_process = require("child_process");
const withOffline = require("next-offline");
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true",
});
const withSourceMaps = require("@zeit/next-source-maps")();
const nextConfig = {
distDir: ".next",
// Workbox options for next-offline
workboxOpts: {
clientsClaim: true,
skipWaiting: true,
},
// Webpack
webpack: (config, { dev, webpack }) => {
// Add build info
const buildTime = new Date().toLocaleString("en-US", {
timeZone: "America/New_York",
});
const gitHash =
process.env.GITHUB_SHA ||
child_process.execSync("git rev-parse HEAD").toString();
config.plugins.push(
new webpack.DefinePlugin({
__BUILD_TIME__: JSON.stringify(buildTime),
__GIT_HASH__: JSON.stringify(gitHash),
__TBA_API_AUTH_KEY__: JSON.stringify(process.env.TBA_API_AUTH_KEY),
__FIREBASE_CONFIG__: JSON.stringify({
apiKey: process.env.FIREBASE_API_KEY,
projectId: process.env.FIREBASE_PROJECT_ID,
appId: process.env.FIREBASE_APP_ID,
}),
__STACKDRIVER_CONFIG__: JSON.stringify({
projectId: process.env.FIREBASE_PROJECT_ID,
key: process.env.STACKDRIVER_API_KEY,
service: "pwa-client",
version: gitHash,
}),
})
);
// Fixes npm packages that depend on `fs` module
config.node = {
fs: "empty",
};
// Optimize images
config.module.rules.push({
test: /\.(jpg|png|gif|svg)$/,
loader: "image-webpack-loader",
// Specify enforce: 'pre' to apply the loader
// before url-loader/svg-url-loader
// and not duplicate it in rules with them
enforce: "pre",
});
// Inline small images
config.module.rules.push({
test: /\.(jpe?g|png|gif)$/,
loader: "url-loader",
options: {
// Images larger than 5 KB won’t be inlined
limit: 5 * 1024,
context: "",
outputPath: "static",
publicPath: "/_next/static",
name: "[path][name].[hash].[ext]",
},
});
config.module.rules.push({
test: /\.svg$/,
loader: "svg-url-loader",
options: {
limit: 5 * 1024, // Images larger than 5 KB won’t be inlined
context: "",
outputPath: "static",
publicPath: "/_next/static",
name: "[path][name].[hash].[ext]",
},
});
// Setup eslint on dev
if (dev) {
config.module.rules.push({
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
emitWarning: true,
},
});
}
return config;
},
};
module.exports = withSourceMaps(withOffline(withBundleAnalyzer(nextConfig)));