-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathnext.ts
57 lines (52 loc) · 1.87 KB
/
next.ts
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
import execa from 'execa';
// @ts-ignore
import withPreconstruct from '@preconstruct/next';
let hasAlreadyStarted = false;
export const withKeystone =
(internalConfig: any = {}) =>
(
phase:
| 'phase-export'
| 'phase-production-build'
| 'phase-production-server'
| 'phase-development-server',
thing: any
) => {
if (phase === 'phase-production-build') {
execa.sync('node', [require.resolve('@keystone-6/core/bin/cli.js'), 'postinstall'], {
stdio: 'inherit',
});
}
if (phase === 'phase-development-server' && !hasAlreadyStarted) {
hasAlreadyStarted = true;
const cliPath = require.resolve('@keystone-6/core/bin/cli.js');
execa.sync('node', [cliPath, 'postinstall', '--fix'], {
stdio: 'inherit',
});
// for some reason things blow up with EADDRINUSE if the dev call happens synchronously here
// so we wait a sec and then do it
setTimeout(() => {
execa('node', [cliPath], {
stdio: 'inherit',
env: { ...process.env, PORT: process.env.PORT || '8000' },
});
}, 100);
}
let internalConfigObj =
typeof internalConfig === 'function' ? internalConfig(phase, thing) : internalConfig;
let originalWebpack = internalConfigObj.webpack;
internalConfigObj.webpack = (webpackConfig: any, options: any) => {
if (options.isServer) {
webpackConfig.externals = [
...webpackConfig.externals,
'@keystone-6/core/___internal-do-not-use-will-break-in-patch/api',
'@keystone-6/core/___internal-do-not-use-will-break-in-patch/next-graphql',
'@keystone-6/core/next',
'@keystone-6/core/system',
'.prisma/client',
];
}
return originalWebpack ? originalWebpack(webpackConfig, options) : webpackConfig;
};
return withPreconstruct(internalConfigObj);
};