Skip to content

Commit 3093172

Browse files
committed
Update UPGRADE.md
1 parent 78b533c commit 3093172

File tree

1 file changed

+137
-9
lines changed

1 file changed

+137
-9
lines changed

UPGRADE.md

Lines changed: 137 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ This will automatically detect whether you are running in serve or build mode an
138138

139139
If your entry point is not `resources/js/app.js`, you should read the [entry point docs](https://github.com/laravel/vite-plugin/blob/docs/docs/vite.md#entry-points) to learn how to use the `@vite` directive with different entry points.
140140

141-
If you are manually including the HMR bundle, you can remove this as well:
142-
143-
```diff
144-
- @env ('local')
145-
- <script src="http://localhost:8080/js/bundle.js"></script>
146-
- @endenv
147-
```
148-
149141
#### React
150142

151143
If you are using React and hot-module replacement, you will need to include an additional directive *before* the `@vite` directive:
@@ -167,7 +159,7 @@ See [this tweet](https://twitter.com/youyuxi/status/1362050255009816577) from Vi
167159
168160
### Remove Laravel Mix
169161

170-
The Laravel Mix plugin can now be uninstalled:
162+
The Laravel Mix package can now be uninstalled:
171163

172164
```shell
173165
npm remove laravel-mix
@@ -239,3 +231,139 @@ If you prefer to build your assets on deploy, instead of committing them to your
239231
```gitignore
240232
/storage/ssr
241233
```
234+
235+
## Migrating from Vite to Laravel Mix
236+
237+
### Install Laravel Mix
238+
239+
First you will need to install Laravel Mix using your npm package manager of choice:
240+
241+
```shell
242+
npm install --save-dev laravel-mix
243+
```
244+
245+
### Configure Mix
246+
247+
Create a `webpack.mix.js` file in the root of your project:
248+
249+
```
250+
const mix = require('laravel-mix');
251+
252+
/*
253+
|--------------------------------------------------------------------------
254+
| Mix Asset Management
255+
|--------------------------------------------------------------------------
256+
|
257+
| Mix provides a clean, fluent API for defining some Webpack build steps
258+
| for your Laravel applications. By default, we are compiling the CSS
259+
| file for the application as well as bundling up all the JS files.
260+
|
261+
*/
262+
263+
mix.js('resources/js/app.js', 'public/js')
264+
.postCss('resources/css/app.css', 'public/css', [
265+
//
266+
]);
267+
```
268+
269+
### Update NPM Scripts
270+
271+
Update your NPM scripts in `package.json`:
272+
273+
```diff
274+
"scripts": {
275+
- "dev": "vite",
276+
- "build": "vite build"
277+
- "ssr:build": "vite build --ssr",
278+
- "ssr:serve": "node storage/ssr/ssr.js"
279+
+ "dev": "npm run development",
280+
+ "development": "mix",
281+
+ "watch": "mix watch",
282+
+ "watch-poll": "mix watch -- --watch-options-poll=1000",
283+
+ "hot": "mix watch --hot",
284+
+ "prod": "npm run production",
285+
+ "production": "mix --production"
286+
}
287+
```
288+
289+
#### Inertia
290+
291+
Vite requires a helper function to import page components which is not required with Laravel Mix.
292+
293+
You can remove this as follows:
294+
295+
```diff
296+
- import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'
297+
298+
createInertiaApp({
299+
title: (title) => `${title} - ${appName}`,
300+
- resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
301+
+ resolve: (name) => require(`./Pages/${name}.vue`),
302+
setup({ el, app, props, plugin }) {
303+
return createApp({ render: () => h(app, props) })
304+
.use(plugin)
305+
.mixin({ methods: { route } })
306+
.mount(el);
307+
},
308+
});
309+
```
310+
311+
### Update environment variables
312+
313+
You will need to update the environment variables that are explicitly exposed in your `.env` files and in hosting environments such as Forge to use the `MIX_` prefix instead of `VITE_`:
314+
315+
```diff
316+
- VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
317+
- VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
318+
+ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
319+
+ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
320+
```
321+
322+
You will also need to update these references in your JavaScript code to use the new variable name and Vite syntax:
323+
324+
```diff
325+
- key: import.meta.env.VITE_PUSHER_APP_KEY,
326+
- cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
327+
+ key: process.env.MIX_PUSHER_APP_KEY,
328+
+ cluster: process.env.MIX_PUSHER_APP_CLUSTER,
329+
```
330+
331+
### Import your CSS from your JavaScript entry point(s)
332+
333+
If you are importing your CSS via JavaScript, you will need to remove this:
334+
335+
```js
336+
-import '../css/app.css'
337+
```
338+
339+
### Replace `@vite` with `mix()`
340+
341+
You will need to replace the `@vite` Blade directive with `<script>` and `<link rel="stylesheet">` tags and the `mix()` helper:
342+
343+
```diff
344+
- @viteReactRefresh
345+
- @vite
346+
+ <link rel="stylesheet" href="{{ mix('css/app.css') }}">
347+
+ <script src="{{ mix('js/app.js') }}" defer></script>
348+
```
349+
350+
### Remove Vite and the Laravel Plugin
351+
352+
Vite and the Laravel Plugin can now be uninstalled:
353+
354+
```shell
355+
npm remove vite laravel-vite-plugin
356+
```
357+
358+
And you may remove your Vite configuration file:
359+
360+
```shell
361+
rm vite.config.js
362+
```
363+
364+
You may also wish to remove any `.gitignore` paths you are no longer using:
365+
366+
```gitignore
367+
- /public/build
368+
- /storage/ssr
369+
```

0 commit comments

Comments
 (0)