-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
79 lines (67 loc) · 2.01 KB
/
Copy pathbuild.js
File metadata and controls
79 lines (67 loc) · 2.01 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
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
/**
* Custom build script for Cloudflare Pages deployment
*
* This script creates a special next.config.js for the production build
* that excludes API routes from the static export.
*/
const fs = require('fs');
const { execSync } = require('child_process');
const path = require('path');
// Backup the original next.config.js
console.log('Backing up next.config.js...');
try {
fs.copyFileSync('next.config.js', 'next.config.js.bak');
} catch (err) {
console.error('Failed to backup next.config.js:', err);
process.exit(1);
}
// Create a simplified next.config.js for the build
console.log('Creating production next.config.js...');
const prodConfig = `
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
images: {
domains: ['boulder.codes', 'buildersroom.boulder.codes'],
unoptimized: true,
},
poweredByHeader: false,
output: 'export',
trailingSlash: true,
}
module.exports = nextConfig
`;
try {
fs.writeFileSync('next.config.js', prodConfig);
} catch (err) {
console.error('Failed to write production next.config.js:', err);
process.exit(1);
}
// Install dependencies
console.log('Installing dependencies...');
try {
execSync('npm install @supabase/supabase-js', { stdio: 'inherit' });
} catch (err) {
console.error('Failed to install dependencies:', err);
// Restore the original config
fs.copyFileSync('next.config.js.bak', 'next.config.js');
fs.unlinkSync('next.config.js.bak');
process.exit(1);
}
// Run the build
console.log('Running the build...');
try {
execSync('next build', { stdio: 'inherit' });
} catch (err) {
console.error('Build failed:', err);
// Restore the original config
fs.copyFileSync('next.config.js.bak', 'next.config.js');
fs.unlinkSync('next.config.js.bak');
process.exit(1);
}
// Restore the original config
console.log('Restoring original next.config.js...');
fs.copyFileSync('next.config.js.bak', 'next.config.js');
fs.unlinkSync('next.config.js.bak');
console.log('Build completed successfully!');