-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnext.config.js
60 lines (53 loc) · 1.94 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
// const withBundleAnalyzer = require("@next/bundle-analyzer")({
// enabled: process.env.ANALYZE === "true",
// });
const CompressionPlugin = require("compression-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const nextConfig = ({
output: "export",
images: { unoptimized: true },
webpack: (config, { isServer }) => {
// Enable gzip compression
config.plugins.push(new CompressionPlugin());
// Optimize JavaScript & CSS
config.optimization = {
...config.optimization,
minimize: true,
mergeDuplicateChunks: true,
moduleIds: "deterministic",
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true, // Removes console logs
dead_code: true, // Removes unused code (Tree Shaking)
reduce_vars: true, // Optimizes variable references
passes: 3, // Applies multiple optimizations
unsafe: true, // Enables more aggressive optimizations
hoist_funs: true, // Moves function declarations to the top
hoist_vars: true, // Moves variable declarations to the top
},
output: {
comments: false, // Removes comments in production
},
},
parallel: true, // Enables multi-threading
extractComments: false, // Prevents separate comment files
}),
new CssMinimizerPlugin(), // Minifies CSS
],
};
// Enable better chunking
config.optimization.splitChunks = {
chunks: "all",
minSize: 30 * 1024, // 30 KB minimum chunk size
maxSize: 250 * 1024, // 250 KB max chunk size
maxInitialRequests: 10, // Allow more parallel requests
},
{ runtimeChunk: "single", // Extract runtime for better caching
}
return config;
},
});
module.exports = nextConfig;