Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.3.x] Support full page reload on blade / arbitrary file changes #43

Merged
merged 4 commits into from
Jun 30, 2022
Merged

[0.3.x] Support full page reload on blade / arbitrary file changes #43

merged 4 commits into from
Jun 30, 2022

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Jun 30, 2022

This PR introduces the ability to preform full page refreshes when specific files change. This is extremely useful when changes are made to Blade files, routes, and other files that will impact the application.

This feature is built atop of the fantastic plugin that was created in the Ruby community: https://github.com/ElMassimo/vite-plugin-full-reload. This Plugin can of course be used directly, however we are introducing some nice defaults and an escape hatch via the Laravel plugin.

refresh: true

This option sets some sensible defaults for the plugin. It will listen for changes on...

routes/**
resources/views/**

Example config...

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js'
            ],
            refresh: true,
        }),
    ],
});

refresh: string

This option allows you to specify a single path to watch.

Example config...

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js'
            ],
            refresh: 'resources/routes/**',
        }),
    ],
});

refresh: string[]

This option allows you to specify a list of paths to watch.

Example config...

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js'
            ],
            refresh: ['resources/routes/**', 'routes/**'],
        }),
    ],
});

refresh: FullRefreshConfig

This option allows you to specify a full config that is passed to the underlying plugin. See their config references for more details...

Example config...

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js'
            ],
            refresh: { 
                paths: ['resources/routes/**', 'routes/**'],
                config: { delay: 300 },
            },
        }),
    ],
});

refresh: FullRefreshConfig[]

This option allows you to specify an array of full configurations that are passed to the underlying plugin and create multiple instances. This is the same as specifying the plugin multiple times which you may want if you want a delay on refreshing some paths and not others because there is a 3rd party build process for certain paths...

Example config...

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js'
            ],
            refresh: [
                { 
                    paths: ['resources/routes/**'],
                },
                { 
                    paths: ['some/other/path**'],
                    config: { delay: 300 },
                },
            ],
        }),
    ],
});

Questions to answer before merging

  • Should we watch for configuration changes (config/**) in the "default" option?
  • Should we watch for .env changes?
  • Should we watch the public directory for changes to static assets?
  • Anything else we should watch for? View Components, Livewire, Inertia related?
  • Do we want anything on even if the config isn't specified i.e. "true" be default and have it as an opt-out feature instead.

Notes

  • I'd like to ask the original plugin maintainer if they would export their interface so we don't have to recreate it here, but I won't do that unless we move ahead with this PR.
  • This will need to be a 0.3.0 release, as the return value of the laravel() function in the vite.config.js file is now an array, which is the documented way of returning multiple plugins from a single plugin. This also opens the door to us bringing in more helpers with good defaults under the hood in the future.
  • This PR is best viewed with the following settings to remove the noise....
    Screen Shot 2022-06-30 at 3 26 23 pm

@driesvints driesvints changed the title [0.3.0] Support full page reload on blade / arbitrary file changes [0.3.x] Support full page reload on blade / arbitrary file changes Jun 30, 2022
@ricardogobbosouza
Copy link

I believe this should be part of this plugin without the need for a third-party library.
ex: https://github.com/innocenzi/laravel-vite/blob/main/vite-plugin-laravel/src/reload.ts

@taylorotwell taylorotwell merged commit d4040a6 into laravel:main Jun 30, 2022
@taylorotwell
Copy link
Member

@timacdonald should we updated the Breeze and Jetstream PHP stacks to include this config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants