|
1 | 1 | /* eslint-disable no-console */ |
2 | 2 |
|
3 | | -import { existsSync } from 'node:fs' |
4 | | -import fs from 'node:fs/promises' |
5 | 3 | import { |
6 | | - DEVTOOLS_CONNECTION_META_FILENAME, |
7 | | - DEVTOOLS_DIRNAME, |
8 | | - DEVTOOLS_DOCK_IMPORTS_FILENAME, |
9 | 4 | DEVTOOLS_MOUNT_PATH, |
10 | | - DEVTOOLS_RPC_DUMP_DIRNAME, |
11 | | - DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME, |
12 | 5 | } from '@vitejs/devtools-kit/constants' |
13 | 6 | import c from 'ansis' |
14 | | -import { dirname, join, relative, resolve } from 'pathe' |
15 | | -import { dirClientStandalone } from '../dirs' |
| 7 | +import { resolve } from 'pathe' |
16 | 8 | import { MARK_NODE } from './constants' |
17 | 9 | import { normalizeHttpServerUrl } from './utils' |
18 | 10 |
|
@@ -93,57 +85,12 @@ export async function build(options: BuildOptions) { |
93 | 85 |
|
94 | 86 | const outDir = resolve(devtools.config.root, options.outDir) |
95 | 87 |
|
96 | | - if (existsSync(outDir)) |
97 | | - await fs.rm(outDir, { recursive: true }) |
98 | | - |
99 | | - const devToolsRoot = join(outDir, DEVTOOLS_DIRNAME) |
100 | | - await fs.mkdir(devToolsRoot, { recursive: true }) |
101 | | - await fs.cp(dirClientStandalone, devToolsRoot, { recursive: true }) |
102 | | - |
103 | | - for (const { baseUrl, distDir } of devtools.context.views.buildStaticDirs) { |
104 | | - console.log(c.cyan`${MARK_NODE} Copying static files from ${distDir} to ${join(outDir, baseUrl)}`) |
105 | | - await fs.mkdir(join(outDir, baseUrl), { recursive: true }) |
106 | | - await fs.cp(distDir, join(outDir, baseUrl), { recursive: true }) |
107 | | - } |
| 88 | + const { buildStaticDevTools } = await import('./build-static') |
| 89 | + await buildStaticDevTools({ |
| 90 | + context: devtools.context, |
| 91 | + outDir, |
| 92 | + }) |
108 | 93 |
|
109 | | - const { renderDockImportsMap } = await import('./plugins/server') |
110 | | - |
111 | | - await fs.mkdir(resolve(devToolsRoot, DEVTOOLS_RPC_DUMP_DIRNAME), { recursive: true }) |
112 | | - await fs.writeFile(resolve(devToolsRoot, DEVTOOLS_CONNECTION_META_FILENAME), JSON.stringify({ backend: 'static' }, null, 2), 'utf-8') |
113 | | - await fs.writeFile(resolve(devToolsRoot, DEVTOOLS_DOCK_IMPORTS_FILENAME), renderDockImportsMap(devtools.context.docks.values()), 'utf-8') |
114 | | - |
115 | | - console.log(c.cyan`${MARK_NODE} Writing RPC dump to ${resolve(devToolsRoot, DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME)}`) |
116 | | - const { collectStaticRpcDump } = await import('./static-dump') |
117 | | - const dump = await collectStaticRpcDump( |
118 | | - devtools.context.rpc.definitions.values(), |
119 | | - devtools.context, |
120 | | - ) |
121 | | - for (const [filepath, data] of Object.entries(dump.files)) { |
122 | | - const fullpath = resolve(devToolsRoot, filepath) |
123 | | - await fs.mkdir(dirname(fullpath), { recursive: true }) |
124 | | - await fs.writeFile(fullpath, JSON.stringify(data, null, 2), 'utf-8') |
125 | | - } |
126 | | - await fs.writeFile(resolve(devToolsRoot, DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME), JSON.stringify(dump.manifest, null, 2), 'utf-8') |
127 | | - await fs.writeFile( |
128 | | - resolve(outDir, 'index.html'), |
129 | | - [ |
130 | | - '<!doctype html>', |
131 | | - '<html lang="en">', |
132 | | - '<head>', |
133 | | - ' <meta charset="UTF-8">', |
134 | | - ' <meta name="viewport" content="width=device-width, initial-scale=1.0">', |
135 | | - ' <title>Vite DevTools</title>', |
136 | | - ` <meta http-equiv="refresh" content="0; url=${DEVTOOLS_MOUNT_PATH}">`, |
137 | | - '</head>', |
138 | | - '<body>', |
139 | | - ` <script>location.replace(${JSON.stringify(DEVTOOLS_MOUNT_PATH)})</script>`, |
140 | | - '</body>', |
141 | | - '</html>', |
142 | | - ].join('\n'), |
143 | | - 'utf-8', |
144 | | - ) |
145 | | - |
146 | | - console.log(c.green`${MARK_NODE} Built to ${relative(devtools.config.root, outDir)}`) |
147 | 94 | console.warn(c.yellow`${MARK_NODE} Static build is still experimental and not yet complete.`) |
148 | 95 | console.warn(c.yellow`${MARK_NODE} Generated output may be missing features and can change without notice.`) |
149 | 96 | } |
0 commit comments