-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathindex.js
69 lines (66 loc) · 2.12 KB
/
index.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
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
import { copyFileSync, unlinkSync } from "fs";
import { dirname, join, resolve } from "path";
import { fileURLToPath, pathToFileURL } from "url";
import { rollup } from "rollup";
import vite from "vite";
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import common from "@rollup/plugin-commonjs";
export default function () {
return {
start(config) {
import(pathToFileURL(join(config.root, "dist", "index.js")));
},
async build(config) {
const __dirname = dirname(fileURLToPath(import.meta.url));
const appRoot = config.solidOptions.appRoot;
await vite.build({
build: {
outDir: "./dist/public",
minify: "terser",
rollupOptions: {
input: resolve(join(config.root, appRoot, `entry-client`)),
output: {
manualChunks: undefined
}
}
}
});
await vite.build({
build: {
ssr: true,
outDir: "./.solid/server",
rollupOptions: {
input: resolve(join(config.root, appRoot, `entry-server`)),
output: {
format: "esm"
}
}
}
});
copyFileSync(
join(config.root, ".solid", "server", `entry-server.js`),
join(config.root, ".solid", "server", "app.js")
);
copyFileSync(join(__dirname, "entry.js"), join(config.root, ".solid", "server", "index.js"));
const bundle = await rollup({
input: join(config.root, ".solid", "server", "index.js"),
plugins: [
json(),
nodeResolve({
preferBuiltins: true,
exportConditions: ["node", "solid"]
}),
common()
],
external: ["undici", "stream/web", "@prisma/client"]
});
// or write the bundle to disk
await bundle.write({ format: "esm", dir: join(config.root, "dist") });
// closes the bundle
await bundle.close();
unlinkSync(join(config.root, "dist", "public", "manifest.json"));
unlinkSync(join(config.root, "dist", "public", "rmanifest.json"));
}
};
}