-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathapp-bundle-ssr.ts
86 lines (76 loc) · 2.37 KB
/
app-bundle-ssr.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
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
/* eslint-disable no-console */
import type { Diagnostic, QwikRollupPluginOptions } from '@qwik.dev/core/optimizer';
import type { InputOptions } from 'rollup';
import type { ReplInputOptions, ReplResult } from '../types';
import { getInputs, getOutput } from './app-bundle-client';
import { replCss, replResolver } from './repl-plugins';
import type { QwikWorkerGlobal } from './repl-service-worker';
export const appBundleSsr = async (options: ReplInputOptions, result: ReplResult) => {
const start = performance.now();
const qwikRollupSsrOpts: QwikRollupPluginOptions = {
target: 'ssr',
buildMode: options.buildMode,
debug: options.debug,
srcInputs: getInputs(options),
entryStrategy: { type: 'hoist' },
manifestInput: result.manifest,
};
console.debug('ssr opts', qwikRollupSsrOpts);
const entry = options.srcInputs.find((i) => i.path.endsWith('entry.server.tsx'));
if (!entry) {
throw new Error(`Missing SSR entry "entry.server.tsx"`);
}
const rollupInputOpts: InputOptions = {
input: entry.path,
plugins: [
replCss(options),
self.qwikOptimizer?.qwikRollup(qwikRollupSsrOpts),
replResolver(options, 'ssr'),
],
onwarn(warning) {
const diagnostic: Diagnostic = {
scope: 'rollup-ssr',
code: warning.code ?? null,
message: warning.message,
category: 'warning',
highlights: [],
file: warning.id || '',
suggestions: null,
};
const loc = warning.loc;
if (loc && loc.file) {
diagnostic.file = loc.file;
diagnostic.highlights!.push({
startCol: loc.column,
endCol: loc.column + 1,
startLine: loc.line,
endLine: loc.line + 1,
lo: 0,
hi: 0,
});
}
result.diagnostics.push(diagnostic);
},
};
const bundle = await self.rollup?.rollup(rollupInputOpts);
if (bundle) {
const generated = await bundle.generate({
format: 'cjs',
inlineDynamicImports: true,
sourcemap: false,
});
result.ssrModules = generated.output.map(getOutput);
result.ssrModules.push({
path: 'q-manifest.json',
code: JSON.stringify(result.manifest, null, 2),
});
}
result.events.push({
kind: 'console-log',
scope: 'build',
start,
end: performance.now(),
message: ['Build SSR'],
});
};
declare const self: QwikWorkerGlobal;