MCPcopy Create free account
hub / github.com/react-static/react-static / buildHTML

Function buildHTML

packages/react-static/src/static/exportRoutes.js:20–95  ·  view source on GitHub ↗
(state)

Source from the content-addressed store, hash-verified

18})
19
20async function buildHTML(state) {
21 const {
22 routes,
23 config: { paths, maxThreads },
24 } = state
25
26 time(chalk.green('[\u2713] HTML Exported'))
27
28 // in case of an absolute path for DIST we must tell node to load the modules
29 // from our project root
30 if (!paths.DIST.startsWith(paths.ROOT)) {
31 process.env.NODE_PATH = paths.NODE_MODULES
32 require('module').Module._initPaths()
33 }
34
35 // Single threaded export
36 if (maxThreads <= 1) {
37 console.log('Exporting HTML...')
38 await require('./exportRoutes.sync').default(state)
39 } else {
40 // Multi-threaded export
41 const threads = Math.min(cores, maxThreads)
42 const htmlProgress = progress(routes.length)
43
44 console.log(`Exporting HTML across ${threads} threads...`)
45
46 const exporters = []
47 for (let i = 0; i < threads; i++) {
48 exporters.push(
49 fork(require.resolve('./exportRoutes.threaded'), [], {
50 env: {
51 ...process.env,
52 REACT_STATIC_THREAD: 'true',
53 },
54 stdio: 'inherit',
55 })
56 )
57 }
58
59 const exporterRoutes = exporters.map(() => [])
60
61 routes.forEach((route, i) => {
62 exporterRoutes[i % exporterRoutes.length].push(route)
63 })
64
65 await Promise.all(
66 exporters.map((exporter, i) => {
67 const routes = exporterRoutes[i]
68 return new Promise((resolve, reject) => {
69 exporter.send({
70 ...state,
71 routes,
72 })
73 exporter.on('message', ({ type, payload }) => {
74 if (type === 'error') {
75 reject(payload)
76 }
77 if (type === 'log') {

Callers 1

exportRoutes.jsFile · 0.85

Calls 2

timeFunction · 0.90
timeEndFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…