Skip to content

Commit 587896a

Browse files
committed
add getting-started/development
1 parent f2ab159 commit 587896a

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Development
3+
order: 300
4+
---
5+
6+
# Development
7+
8+
NativePHP isn't prescriptive about how you develop your application. You can build it in the way you're most comfortable
9+
and familiar with, just as if you were building a traditional web application.
10+
11+
The only difference comes in the feedback cycle. Instead of switching to and refreshing your browser, you'll need to
12+
be serving your application using `php artisan native:serve` and refreshing (and in some cases restarting) your
13+
application to see changes.
14+
15+
## What does the `native:serve` command do?
16+
17+
The `native:serve` command runs the Electron/Tauri 'debug build' commands, which build your application with various
18+
debug options set to help make debugging easier, such as allowing you to show the Dev Tools.
19+
20+
It also keeps the connection to the terminal open so you can see and inspect useful output from your app, like logs,
21+
in real time.
22+
23+
These builds are unsigned and not meant for distribution. They do not go through various optimizations typically done
24+
when [building your application for production](/docs/publishing) and so they expose more about the inner workings of
25+
the code than you would typically want to share with your users.
26+
27+
A major part of the build process, even for debug builds, involves _copying_ your application code into the runtime's
28+
build environment. This means that changes you make to your application code _will not_ be reflected in your running
29+
application until you restart it.
30+
31+
You can stop the `native:serve` command by pressing `Ctrl-C` on your keyboard in the terminal window it's running in.
32+
33+
Alternatively, you can use hot reloading.
34+
35+
## Hot Reloading
36+
37+
Hot reloading is an awesome feature for automatically seeing changes to your application during development. NativePHP
38+
supports hot reloading of certain files within its core and your application, but it does _not_ watch all of your
39+
source code for changes. It is left to you to determine how you want to approach this.
40+
41+
If you're using Vite, hot reloading will just work inside your app as long as you've booted your Vite dev server and
42+
[included the Vite script tag](https://laravel.com/docs/vite#loading-your-scripts-and-styles) in your views
43+
(ideally in your app's main layout file).
44+
45+
46+
You can do this easily in Blade using the `@@vite` directive.
47+
48+
Then, in a separate terminal session to your `php artisan native:serve`, from the root folder of your application, run:
49+
50+
```shell
51+
npm run dev
52+
```
53+
54+
Now changes you make to files in your source code will cause a hot reload in your running application.
55+
56+
Which files trigger reloads will depend on your Vite configuration.
57+
58+
## First run
59+
60+
When your application runs for the first time, a number of things occur.
61+
62+
NativePHP will:
63+
64+
1. Create the `appdata` folder - where this is created depends which platform you're developing on. It is named
65+
according to your `nativephp.app_id` config value (which is based on the `NATIVEPHP_APP_ID` env variable).
66+
2. Create a SQLite database
67+
3. Migrate the database
68+
69+
This is identical to what will happen when a new user runs a production build of your app for the first time on their
70+
device.
71+
72+
**If you change your `app_id`, a new `appdata` folder may need to be created and all of these steps will need to run
73+
again. No previous files will be deleted.**
74+
75+
## Subsequent runs
76+
77+
Every time your application boots, NativePHP checks that these files exist and creates them if they don't. It also tries
78+
to run your migrations. This is done with the `--force` flag so that it is fully automated even in production.

0 commit comments

Comments
 (0)