forked from leebenson/reactql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic.ts
45 lines (35 loc) · 1.25 KB
/
static.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
// Runner (static)
// ----------------------------------------------------------------------------
// IMPORTS
/* Node */
import * as path from "path";
/* NPM */
import * as chalk from "chalk";
/* Local */
import { build, common, app, staticCompiler, devServer } from "./app";
import clientConfig from "../webpack/client";
// ----------------------------------------------------------------------------
common.spinner.info(chalk.default.bgBlue("Static mode"));
void (async () => {
// Production?
if (common.isProduction) {
common.spinner.info("Building production files...");
await build(true /* build in static mode */);
common.spinner.succeed("Finished building");
return;
}
// Development...
common.spinner.info("Building development server...");
app.listen({ port: common.port, host: common.host }, async () => {
// Build the static dev server
const middleware = await devServer(app, staticCompiler);
// Fallback to /index.html on 404 routes, for client-side SPAs
app.use(async ctx => {
const filename = path.resolve(clientConfig.output.path, "index.html");
ctx.response.type = "html";
ctx.response.body = middleware.devMiddleware.fileSystem.createReadStream(
filename
);
});
});
})();