-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
51 lines (46 loc) · 1.51 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
/* eslint-disable @typescript-eslint/no-var-requires */
/* @ts-check */
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
images: {
unoptimized: false,
domains: ['s3-eu-west-1.amazonaws.com'],
// Should ideally match `screens` in `tailwind.config.js`
deviceSizes: [480, 768, 1024, 1440],
},
};
// Any environment variables that are listed in .env.example are considered
// required. We read all environment variables from .env.example and check if
// they are set. If any are missing from process.env, we fail the build. Else
// we print the config to the console and continue as normal.
if (process.env.NODE_ENV === 'production') {
const fs = require('fs');
const path = require('path');
let missingEnvVars = '';
const exampleEnvFilePath = path.resolve(process.cwd(), '.env.example');
if (fs.existsSync(exampleEnvFilePath)) {
const content = fs.readFileSync(exampleEnvFilePath, 'utf8');
const lines = content.split(/\r?\n/);
for (const line of lines) {
if (line.startsWith('#') || !line) continue; // Skip comments and empty lines
const [key, _value] = line.split('=');
if (!key) continue;
if (typeof process.env[key] === 'undefined') {
missingEnvVars += ' - ' + key + '\n';
}
}
}
if (missingEnvVars) {
console.error(
'The following environment variables were not set. Please set them and try again.\n' +
missingEnvVars,
);
process.exit(1);
} else {
console.info(
'\u2705 next.config.js',
JSON.stringify(module.exports, null, 2),
);
}
}