-
Notifications
You must be signed in to change notification settings - Fork 51k
Expand file tree
/
Copy pathvercel-build.js
More file actions
88 lines (80 loc) · 2.15 KB
/
vercel-build.js
File metadata and controls
88 lines (80 loc) · 2.15 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
80
81
82
83
84
85
86
87
88
const childProcess = require('child_process');
const fs = require('fs/promises');
const path = require('path');
/**
* vite-plugin-ssr for create-react-app
*/
async function main() {
const projectDir = path.resolve(__dirname, '..');
const craBuildDir = path.join(projectDir, 'build');
const buildOutputDir = path.join(projectDir, '.vercel/output');
const buildStaticOutputDir = path.join(buildOutputDir, 'static');
const buildFunctionsOutputDir = path.join(buildOutputDir, 'functions');
childProcess.execSync('yarn build', {stdio: 'inherit'});
// reduce amount of n_m shipped
childProcess.execSync('yarn install --production', {stdio: 'inherit'});
await fs.rm(buildOutputDir, {recursive: true, force: true});
await fs.mkdir(buildOutputDir, {recursive: true});
await fs.cp(
path.join(craBuildDir, 'static'),
path.join(buildStaticOutputDir, 'static'),
{
recursive: true,
}
);
const indexFunctionDir = path.join(buildFunctionsOutputDir, 'index.func');
await fs.mkdir(indexFunctionDir, {recursive: true});
const indexFunctionConfig = {
handler: 'server/index.js',
launcherType: 'Nodejs',
runtime: 'nodejs22.x',
environment: {},
};
await fs.writeFile(
path.join(indexFunctionDir, '.vc-config.json'),
JSON.stringify(indexFunctionConfig, null, 2)
);
await fs.cp(
path.join(projectDir, 'package.json'),
path.join(indexFunctionDir, 'package.json'),
{
recursive: true,
}
);
await fs.cp(
path.join(projectDir, 'build'),
path.join(indexFunctionDir, 'build'),
{
recursive: true,
}
);
await fs.cp(
path.join(projectDir, 'node_modules'),
path.join(indexFunctionDir, 'node_modules'),
{
recursive: true,
}
);
await fs.cp(
path.join(projectDir, 'server'),
path.join(indexFunctionDir, 'server'),
{
recursive: true,
}
);
await fs.cp(
path.join(projectDir, 'src'),
path.join(indexFunctionDir, 'src'),
{
recursive: true,
}
);
const buildOutputConfig = {
version: 3,
};
await fs.writeFile(
path.join(buildOutputDir, 'config.json'),
JSON.stringify(buildOutputConfig, null, 2)
);
}
main();