Skip to content

Commit 37ec798

Browse files
jessarchertimacdonaldtaylorotwell
authored
[0.x] Documentation updates (#35)
* Update semi-colon usage in examples * Add section on test helpers * add note about leading slashes in aliases * remove additional alias * improve wording * Add documentation link to README * Update UPGRADE.md Co-authored-by: Jess Archer <[email protected]> * Update UPGRADE.md Co-authored-by: Jess Archer <[email protected]> * Update UPGRADE.md Co-authored-by: Tim MacDonald <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent fa1bf8a commit 37ec798

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This plugin configures Vite for use with a Laravel backend server.
1313

1414
## Official Documentation
1515

16-
Coming soon.
16+
Documentation for the Laravel Vite plugin can be found on the [Laravel website](https://laravel.com/docs/vite).
1717

1818
## Contributing
1919

UPGRADE.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ npm install --save-dev @vitejs/plugin-react
2727
Create a `vite.config.js` file in the root of your project:
2828

2929
```js
30-
import { defineConfig } from 'vite'
31-
import laravel from 'laravel-vite-plugin'
32-
// import react from '@vitejs/plugin-react'
33-
// import vue from '@vitejs/plugin-vue'
30+
import { defineConfig } from 'vite';
31+
import laravel from 'laravel-vite-plugin';
32+
// import react from '@vitejs/plugin-react';
33+
// import vue from '@vitejs/plugin-vue';
3434

3535
export default defineConfig({
3636
plugins: [
@@ -48,11 +48,33 @@ export default defineConfig({
4848
// },
4949
// }),
5050
],
51-
})
51+
});
5252
```
5353

5454
If you are building an SPA, you will get a better developer experience by removing the CSS entry point above and [importing your CSS from Javascript](#importing-your-css-from-your-javascript-entry-points).
5555

56+
#### Update Aliases
57+
58+
If you are migrating aliases from your `webpack.mix.js` file to your `vite.config.js` file, you should ensure that the paths start with `/`. For example, `resources/js` would become `/resources/js`:
59+
60+
```js
61+
export default defineConfig({
62+
plugins: [
63+
laravel([
64+
'resources/css/app.css',
65+
'resources/js/app.js',
66+
]),
67+
],
68+
resolve: {
69+
alias: {
70+
'@': '/resources/js'
71+
}
72+
}
73+
});
74+
```
75+
76+
For your convenience, the Laravel Vite plugin automatically adds an `@` alias for your `/resources/js` directory. If you do not need to customize your aliases, you may omit this section from your `vite.config.js` file.
77+
5678
### Update NPM scripts
5779

5880
Update your NPM scripts in `package.json`:
@@ -82,7 +104,7 @@ Inertia makes use of a `require()` call that is more complex to replicate with V
82104
The following function can be used instead:
83105

84106
```diff
85-
+ import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'
107+
+ import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
86108

87109
createInertiaApp({
88110
title: (title) => `${title} - ${appName}`,
@@ -166,8 +188,8 @@ See [this tweet](https://twitter.com/youyuxi/status/1362050255009816577) from Vi
166188
### Vue imports must include the `.vue` extension
167189

168190
```diff
169-
- import Button from './Button'
170-
+ import Button from './Button.vue'
191+
- import Button from './Button';
192+
+ import Button from './Button.vue';
171193
```
172194

173195
### Remove Laravel Mix
@@ -186,6 +208,15 @@ rm webpack.mix.js
186208

187209
If you are using StyleCI and have ignored the `webpack.mix.js` file in your configuration, you may also wish to remove the ignore rule.
188210

211+
### Update Test Helpers
212+
213+
If you are using the `$this->withoutMix();` helper in your tests, you should replace this with `$this->withoutVite()`:
214+
215+
```diff
216+
- $this->withoutMix();
217+
+ $this->withoutVite();
218+
```
219+
189220
### Optional: Configure Tailwind
190221

191222
If you are using Tailwind, perhaps with one of Laravel's starter kits, you will need to create a `postcss.config.js` file. Tailwind can generate this for you automatically:
@@ -226,8 +257,8 @@ rm webpack.ssr.mix.js
226257
In most cases, you won't need a dedicated SSR configuration file when using Vite. You can specify your SSR entry point by passing a configuration option to the Laravel plugin:
227258

228259
```js
229-
import { defineConfig } from 'vite'
230-
import laravel from 'laravel-vite-plugin'
260+
import { defineConfig } from 'vite';
261+
import laravel from 'laravel-vite-plugin';
231262

232263
export default defineConfig({
233264
plugins: [
@@ -236,7 +267,7 @@ export default defineConfig({
236267
ssr: 'resources/js/ssr.js',
237268
}),
238269
],
239-
})
270+
});
240271
```
241272

242273
You may wish to add the following additional scripts to your `package.json`:
@@ -334,7 +365,7 @@ Update your NPM scripts in `package.json`:
334365
Vite requires a helper function to import page components which is not required with Laravel Mix. You can remove this as follows:
335366

336367
```diff
337-
- import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'
368+
- import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
338369

339370
createInertiaApp({
340371
title: (title) => `${title} - ${appName}`,
@@ -374,7 +405,7 @@ You will also need to update these references in your JavaScript code to use the
374405
If you are importing your CSS via JavaScript, you will need to remove these statements:
375406

376407
```js
377-
- import '../css/app.css'
408+
- import '../css/app.css';
378409
```
379410

380411
### Replace `@vite` with `mix()`

0 commit comments

Comments
 (0)