Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit ec06e5e

Browse files
committed
README update
1 parent d843113 commit ec06e5e

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

README.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
A highly opinionated packaged boilerplate solution for installing Vite, Tailwind and Inertia (along a few other things) into a Laravel app.
66

77
## What
8+
89
Vitamin will install all the bits and pieces needed (plus a few others, because I use them regularly) to get Vite, Tailwind, Vue 3, Inertia and Ziggy working with Laravel while running on a local Valet installation. This is super-duper opinionated, but could be customized to include other stuff.
910

1011
I've also included some packages that I use often, but they can be removed if you don't need them.
1112

1213
## Installation
14+
1315
Like everything Laravel, install Vitamin via Composer:
1416

1517
```shell
@@ -21,6 +23,7 @@ Once installed, run the Vitamin Artisan command:
2123
```
2224
php ./artisan vitamin:init
2325
```
26+
2427
Vitamin will guide you through a few prompts and then install the entire boilerplate including required NPM and Composer packages. You can modify these as you need later, but you should let the process complete.
2528

2629
Link a Valet host if you haven't already:
@@ -67,17 +70,24 @@ The following NPM packages are installed:
6770
- [vue](https://github.com/vuejs/vue)
6871

6972
## Usage
70-
Vitamin will add a few NPM scripts (note that it expects Yarn to be present during installation). To start a new Vite dev server, run:
73+
74+
Vitamin will add a few NPM scripts. Previous versions required that the "Yarn" dependency manager was installed. Later versions will ask if you prefer "npm" or "yarn".
75+
76+
Once all installation is complete, you can start a new Vite dev server, using the `vitamin:serve` Artisan command. A `dev` NPM script has also been added so you can start the dev server using your node dependency manager as well:
7177

7278
```shell
7379
yarn dev
7480

7581
// or
7682

83+
npm run dev
84+
85+
// or
86+
7787
php ./artisan vitamin:serve
7888
```
7989

80-
Vite will run a dev server on your local machine on port 3000 (it will automatically increment the port number if 3000 isn't available). Once it's running, you should see something like:
90+
Vite will run a dev server on your local machine on port 3000. Once it's running, you should see something like:
8191

8292
```
8393
vite v2.4.4 dev server running at:
@@ -88,28 +98,41 @@ Vite will run a dev server on your local machine on port 3000 (it will automatic
8898
ready in 571ms.
8999
```
90100

91-
This is the dev server. You'll also need to make sure you create a new Valet link, then you should be able to visit your new project at `http://vitamin.test` or whatever your Valet address is.
101+
You'll need to create a new Valet link and then you should be able to visit your new project at `http://vitamin.test` or whatever your dev address is.
92102

93103
### Port number
94-
By default Vite will run on port 3000 but will increment the port number by 1 if 3000 is already in use. Vitamin won't know that the port number has been incremented, but you can specify a port number by changing the `port` setting in the `vitamin.php` config file.
104+
105+
By default Vite will run on port 3000. You can specifty the port number if you need to by changing the `port` setting in the `vitamin.php` config file.
95106

96107
```php
97108
return [
98-
"port" => 3002,
99-
//...
109+
"port" => 3002,
110+
//...
100111
]
101112
```
102113

114+
Or by passing the port number to the `vitamin:serve` command:
115+
116+
```shell
117+
php ./artisan vitamin:serve --port=3010
118+
```
119+
103120
### Building for production
121+
104122
To build your project for production:
105123

106124
```shell
107125
yarn prod
126+
127+
// or
128+
129+
npm run prod
108130
```
109131

110132
As simple as that. Depending on the size of your project, building should be a fair amount quicker than Webpack. Once complete, there is a new `public/build` directory. You'll probably want to add that to your `.gitignore` file. It's not wize to include compiled assets in your repo.
111133

112134
### The View Composer
135+
113136
The heart of Vitamin is a simple Laravel view composer that ensures the correct resources are inserted into the page. The view composer is included with the package, but you can extend it if you want to make changes. For example, if you're using TypeScript, you'll probably want to change the `app.js` file for an `app.ts` file and you'll need to update the view composer to point to the correct filename. To do this, create a new `AppComposer` class in your project and extend the `TPG\Vitamin\Composers\AppComposer` class. You can then override the `$jsPath` property:
114137

115138
```php
@@ -145,12 +168,15 @@ public function compose(View $view): void
145168
If you're not familiar with Laravel view composers, take a look at the documentation [here](https://laravel.com/docs/views#view-composers).
146169

147170
### Valet
148-
During development, all assets are served from the dev server running at port 3000. Vitamin includes a custom Valet driver (there should be a `LocalValetDriver.php` file in your project root) that will ensure that assets served from `node_modules` are served correctly. I found that this was needed in a few edge cases, which is why I included it. The custom driver extends the default `LaravelValetDriver` so you shouldn't have any problems running Valet.
171+
172+
During development, all assets are served from the dev server running at port 3000. Vitamin includes a custom Valet driver (there should be a `LocalValetDriver.php` file in your project root) that will ensure that assets served from `node_modules` are served correctly. I found that this was needed in a few edge cases. The custom driver extends the default `LaravelValetDriver` so you shouldn't be running into any issues. However, if you find that you have issues using the custom driver, simply delete the file and Valet will go on using it's default driver.
149173

150174
### Inertia
151-
Inertia is my go to these days, so Vitamin will set it up by default. During initialisation, you're asked where your Vue components are stored. You can customize this location in `app.js` if you wish. Vite will load your Vue pages from there. The Inertia documentation uses `resources/js/Pages`, so Vitamin will make that suggestion. However, technically, you can put them anywhere. The only requirement is that the location must be child of the JS path.
175+
176+
Inertia is my go to these days, so Vitamin will set it up by default. During initialisation, you're asked where your Vue components are stored. You can customize this location in `app.js` if you wish. Vite will load your Vue pages from there. The Inertia documentation uses `resources/js/Pages`, so Vitamin will make that suggestion. However, technically, you can put them anywhere. The only requirement Vitamin imposes is that the location must be child of the JS path.
152177

153178
### Ziggy
179+
154180
Ziggy is a JavaScript route helper for Laravel. If allows you to use your Laravel defined routes from within your JavaScript front-end. Vitamin comes with a `Router` script that provides a `route` function. You can import this into any Vue file to get access to your Laravel routes:
155181

156182
```javascript
@@ -161,16 +187,19 @@ route('home');
161187

162188
Vitamin sets up Ziggy routes in the `resources/js/Scripts/Routing/Ziggy.js` file. This file needs to be regenerated each time your change your Laravel routes. Vitamin does this automatically by creating a simple Vite plugin that will run the `yarn routes` script each time a Laravel routes file changes. However, if you ever need to rebuild the routes, simply run `yarn routes` yourself. If you. change the name of this file or want to place it somewhere else, remember to update the reference in the `Router.js` file as well.
163189

164-
In previous versions of Vitamin, the Ziggy Vue plugin was used, but since I don't use that anymore and now have
190+
> In previous versions of Vitamin, the Ziggy Vue plugin was used, but I've found the newer approach to be more flexible and is better when using the Vue composition API.
165191
166192
## TLS Certificates
167-
It's possible to get all of this to work with TLS as well so you can use an `https` address during development. First, you need to get Valet to secure your site. Valet provides a simple solution for this. If you're serving your site at `mysite.test` then you can get Valet to generate a new certificate:
193+
194+
It's possible to get all of this to work with TLS as well so you can use an `https` address during development. First, you need to get Valet to secure your site which already provides a simple solution for this. If you're serving your site at `mysite.test` then you can get Valet to generate a new certificate:
168195

169196
```shell
170197
valet secure mysite
171198
```
172199

173-
It will likely ask you for your password. You'll also need to get Vite to do the same thing. The easiest way to do so is to use the `mkcert` Vite plugin:
200+
It will likely ask you for your password.
201+
202+
You'll also need to get Vite to do the same thing. The easiest way to do this is to use the `mkcert` Vite plugin:
174203

175204
```shell
176205
yarn add vite-plugin-mkcert -D
@@ -195,14 +224,12 @@ export default({command}) => ({
195224
});
196225
```
197226

198-
Lastly update the `package.json` file to tell Vite to run in `https` mode:
227+
Lastly, update the `vitamin.php` config file and set the `https` option to true:
199228

200229
```json
201230
{
202-
"scripts": {
203-
"dev": "vite serve --host=mysite.test --https"
204-
}
231+
"https": true
205232
}
206233
```
207234

208-
The first time you run `yarn dev`, you'll likely be asked for your password so that the mkcert plugin can generate a new certificate. I might add an HTTPS question to the Vitamin setup at some point. If and when I do, I'll update this.
235+
The first time you run `yarn dev`, you'll likely be asked for your password so that the mkcert plugin can generate a new certificate.

0 commit comments

Comments
 (0)