(state)
| 18 | }) |
| 19 | |
| 20 | async 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') { |
no test coverage detected
searching dependent graphs…