forked from ProjectEvergreen/greenwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
62 lines (53 loc) · 2.08 KB
/
Copy pathbuild.js
File metadata and controls
62 lines (53 loc) · 2.08 KB
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
import { bundleCompilation } from "../lifecycles/bundle.js";
import { copyAssets } from "../lifecycles/copy.js";
import { getDevServer } from "../lifecycles/serve.js";
import {
preRenderCompilationWorker,
preRenderCompilationCustom,
staticRenderCompilation,
} from "../lifecycles/prerender.js";
const runProductionBuild = async (compilation) => {
const { prerender, activeContent, plugins } = compilation.config;
const prerenderPlugin = compilation.config.plugins.find((plugin) => plugin.type === "renderer")
? compilation.config.plugins.find((plugin) => plugin.type === "renderer").provider(compilation)
: {};
const adapterPlugin = compilation.config.plugins.find((plugin) => plugin.type === "adapter")
? compilation.config.plugins.find((plugin) => plugin.type === "adapter").provider(compilation)
: null;
if (prerender) {
// start any of the user's server plugins if needed
const servers = [
...compilation.config.plugins
.filter((plugin) => {
return plugin.type === "server" && !plugin.isGreenwoodDefaultPlugin;
})
.map((plugin) => plugin.provider(compilation)),
];
if (activeContent) {
(
await getDevServer({
...compilation,
// prune for the content as data plugin and start the dev server with only that plugin enabled
plugins: [plugins.find((plugin) => plugin.name === "plugin-active-content")],
})
).listen(compilation.config.devServer.port, () => {
console.info("Initializing active content...");
});
}
await Promise.all(servers.map((server) => server.start()));
if (prerenderPlugin.executeModuleUrl) {
await preRenderCompilationWorker(compilation, prerenderPlugin);
} else {
await preRenderCompilationCustom(compilation, prerenderPlugin);
}
} else {
await staticRenderCompilation(compilation);
}
console.info("success, done generating all pages!");
await bundleCompilation(compilation);
await copyAssets(compilation);
if (adapterPlugin) {
await adapterPlugin();
}
};
export { runProductionBuild };