-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
39 lines (36 loc) · 1.16 KB
/
Copy pathnext.config.js
File metadata and controls
39 lines (36 loc) · 1.16 KB
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
/** @type {import('next').NextConfig} */
const fs = require("fs");
const path = require("path");
// Read version from package.json
function getPackageVersion() {
try {
const packagePath = path.join(__dirname, "package.json");
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
return packageJson.version;
} catch (error) {
console.warn("Could not read package.json version:", error);
return "unknown";
}
}
const nextConfig = {
env: {
NEXT_PUBLIC_APP_VERSION: getPackageVersion(),
},
// Webpack configuration (for non-Turbopack builds)
webpack: (config, { dev, isServer }) => {
// Only in production builds
if (!dev && !isServer) {
// Ensure version is available during build
config.plugins.push({
apply: (compiler) => {
compiler.hooks.beforeCompile.tap("SetVersion", () => {
process.env.NEXT_PUBLIC_APP_VERSION =
getPackageVersion();
});
},
});
}
return config;
},
};
module.exports = nextConfig;