Skip to content

Commit bc844ff

Browse files
authored
fix: preserve user app output in build.withApp mode (#258)
1 parent b04bc83 commit bc844ff

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

packages/core/src/node/build-static.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import { MARK_NODE } from './constants'
1919
export interface BuildStaticOptions {
2020
context: DevToolsNodeContext
2121
outDir: string
22+
withApp?: boolean
2223
}
2324

2425
export async function buildStaticDevTools(options: BuildStaticOptions): Promise<void> {
25-
const { context, outDir } = options
26+
const { context, outDir, withApp } = options
2627

27-
if (existsSync(outDir))
28+
if (!withApp && existsSync(outDir))
2829
await fs.rm(outDir, { recursive: true })
2930

3031
const devToolsRoot = join(outDir, DEVTOOLS_DIRNAME)
@@ -55,24 +56,26 @@ export async function buildStaticDevTools(options: BuildStaticOptions): Promise<
5556
await fs.writeFile(fullpath, JSON.stringify(data, null, 2), 'utf-8')
5657
}
5758
await fs.writeFile(resolve(devToolsRoot, DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME), JSON.stringify(dump.manifest, null, 2), 'utf-8')
58-
await fs.writeFile(
59-
resolve(outDir, 'index.html'),
60-
[
61-
'<!doctype html>',
62-
'<html lang="en">',
63-
'<head>',
64-
' <meta charset="UTF-8">',
65-
' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
66-
' <title>Vite DevTools</title>',
67-
` <meta http-equiv="refresh" content="0; url=${DEVTOOLS_MOUNT_PATH}">`,
68-
'</head>',
69-
'<body>',
70-
` <script>location.replace(${JSON.stringify(DEVTOOLS_MOUNT_PATH)})</script>`,
71-
'</body>',
72-
'</html>',
73-
].join('\n'),
74-
'utf-8',
75-
)
59+
if (!existsSync(resolve(outDir, 'index.html'))) {
60+
await fs.writeFile(
61+
resolve(outDir, 'index.html'),
62+
[
63+
'<!doctype html>',
64+
'<html lang="en">',
65+
'<head>',
66+
' <meta charset="UTF-8">',
67+
' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
68+
' <title>Vite DevTools</title>',
69+
` <meta http-equiv="refresh" content="0; url=${DEVTOOLS_MOUNT_PATH}">`,
70+
'</head>',
71+
'<body>',
72+
` <script>location.replace(${JSON.stringify(DEVTOOLS_MOUNT_PATH)})</script>`,
73+
'</body>',
74+
'</html>',
75+
].join('\n'),
76+
'utf-8',
77+
)
78+
}
7679

7780
console.log(c.green`${MARK_NODE} Built DevTools to ${relative(context.cwd, outDir)}`)
7881
}

packages/core/src/node/plugins/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function DevToolsBuild(options: DevToolsBuildOptions = {}): Plugin {
3535
: resolve(resolvedConfig.root, resolvedConfig.build.outDir)
3636

3737
const { buildStaticDevTools } = await import('../build-static')
38-
await buildStaticDevTools({ context, outDir })
38+
await buildStaticDevTools({ context, outDir, withApp: true })
3939
},
4040
}
4141
}

0 commit comments

Comments
 (0)