-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
37 lines (29 loc) · 984 Bytes
/
plugin.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
import { readFileSync } from 'fs';
const sym = 'sveltekit-adapter-custom.http-server';
/** @returns {import('./plugin').default} */
export default function () {
let command;
let root;
return {
name: 'sveltekit-adapter-custom',
configResolved(config) {
command = config.command;
root = config.root;
},
configureServer({ httpServer }) {
globalThis[Symbol.for(sym)] = httpServer;
},
configurePreviewServer({ httpServer }) {
globalThis[Symbol.for(sym)] = httpServer;
},
load(file) {
if (command !== 'build' && file === `${root}/src/hooks.server.ts`) {
const lines = readFileSync(file, 'utf-8').split('\n');
lines.push('');
lines.push(`setup(globalThis[Symbol.for('${sym}')]);`);
lines.push('');
return { code: lines.join('\n') };
}
},
};
}