You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a `vite.config.js` file in the root of your project:
28
28
29
29
```js
30
-
import { defineConfig } from'vite'
31
-
importlaravelfrom'laravel-vite-plugin'
32
-
// import react from '@vitejs/plugin-react'
33
-
// import vue from '@vitejs/plugin-vue'
30
+
import { defineConfig } from'vite';
31
+
importlaravelfrom'laravel-vite-plugin';
32
+
// import react from '@vitejs/plugin-react';
33
+
// import vue from '@vitejs/plugin-vue';
34
34
35
35
exportdefaultdefineConfig({
36
36
plugins: [
@@ -48,11 +48,33 @@ export default defineConfig({
48
48
// },
49
49
// }),
50
50
],
51
-
})
51
+
});
52
52
```
53
53
54
54
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).
55
55
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
+
exportdefaultdefineConfig({
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
+
56
78
### Update NPM scripts
57
79
58
80
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
82
104
The following function can be used instead:
83
105
84
106
```diff
85
-
+ import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'
107
+
+ import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
86
108
87
109
createInertiaApp({
88
110
title: (title) => `${title} - ${appName}`,
@@ -166,8 +188,8 @@ See [this tweet](https://twitter.com/youyuxi/status/1362050255009816577) from Vi
166
188
### Vue imports must include the `.vue` extension
167
189
168
190
```diff
169
-
- import Button from './Button'
170
-
+ import Button from './Button.vue'
191
+
- import Button from './Button';
192
+
+ import Button from './Button.vue';
171
193
```
172
194
173
195
### Remove Laravel Mix
@@ -186,6 +208,15 @@ rm webpack.mix.js
186
208
187
209
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.
188
210
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
+
189
220
### Optional: Configure Tailwind
190
221
191
222
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
226
257
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:
227
258
228
259
```js
229
-
import { defineConfig } from'vite'
230
-
importlaravelfrom'laravel-vite-plugin'
260
+
import { defineConfig } from'vite';
261
+
importlaravelfrom'laravel-vite-plugin';
231
262
232
263
exportdefaultdefineConfig({
233
264
plugins: [
@@ -236,7 +267,7 @@ export default defineConfig({
236
267
ssr:'resources/js/ssr.js',
237
268
}),
238
269
],
239
-
})
270
+
});
240
271
```
241
272
242
273
You may wish to add the following additional scripts to your `package.json`:
@@ -334,7 +365,7 @@ Update your NPM scripts in `package.json`:
334
365
Vite requires a helper function to import page components which is not required with Laravel Mix. You can remove this as follows:
335
366
336
367
```diff
337
-
- import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'
368
+
- import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
338
369
339
370
createInertiaApp({
340
371
title: (title) => `${title} - ${appName}`,
@@ -374,7 +405,7 @@ You will also need to update these references in your JavaScript code to use the
374
405
If you are importing your CSS via JavaScript, you will need to remove these statements:
0 commit comments