Skip to content

Commit ea51504

Browse files
authored
fix(cta): stop react recipe from opening in browser, closes #2793 (#2988)
1 parent 1c7ee6e commit ea51504

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-tauri-app": patch
3+
---
4+
5+
Stop react recipe from opening in browser by default.

tooling/create-tauri-app/src/helpers/update-package-json.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import { join } from 'path'
77

88
interface Package {
99
name?: string
10-
scripts?: {}
10+
scripts?: Record<string, string>
1111
}
1212

13-
export function updatePackageJson(appDirectory: string, appName: string): void {
13+
export function updatePackageJson(
14+
appDirectory: string,
15+
appName: string,
16+
recipeShortName: string
17+
): void {
1418
const pkgPath = join(appDirectory, 'package.json')
1519
const pkgString = readFileSync(pkgPath, 'utf8')
1620
const pkg = JSON.parse(pkgString) as Package
@@ -19,6 +23,9 @@ export function updatePackageJson(appDirectory: string, appName: string): void {
1923
name: appName,
2024
scripts: {
2125
...pkg.scripts,
26+
start: `${recipeShortName === 'cra' ? 'cross-env BROWSER=none ' : ''}${
27+
pkg.scripts?.start as string
28+
}`,
2229
tauri: 'tauri'
2330
}
2431
}

tooling/create-tauri-app/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ const runInit = async (argv: Argv): Promise<void> => {
370370
})
371371

372372
logStep(`Updating ${reset(yellow('"package.json"'))}`)
373-
updatePackageJson(appDirectory, appName)
373+
updatePackageJson(appDirectory, appName, recipe.shortName)
374374

375375
logStep(`Running ${reset(yellow('"tauri init"'))}`)
376376
const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b)

tooling/create-tauri-app/src/recipes/react.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const cra: Recipe = {
4646
packageManager === 'npm' ? 'npm run' : packageManager
4747
} build`
4848
}),
49-
extraNpmDevDependencies: [],
49+
extraNpmDevDependencies: ['cross-env'],
5050
extraNpmDependencies: [],
5151
extraQuestions: ({ ci }) => {
5252
return [

0 commit comments

Comments
 (0)