Coder Social home page Coder Social logo

HMR + Browsersync about inertia-laravel HOT 4 CLOSED

inertiajs avatar inertiajs commented on July 19, 2024
HMR + Browsersync

from inertia-laravel.

Comments (4)

sebastiandedeyne avatar sebastiandedeyne commented on July 19, 2024 5

I got HMR working with Inertia in most cases. There's one issue where there's odd behaviour when a hot reload happens after you've navigated with Inertia, but I solved that by doing a full refresh in those cases.

I'm not using Laravel Mix, but my webpack is set up to mirror Mix as much as possible, so I don't think it really matters much. However this is without BrowserSync.

I added this to my main app.js file and it seems to work:

if (module.hot) {
    const firstVisit = window.location.pathname;

    module.hot.accept();

    module.hot.dispose(() => {
        if (firstVisit !== window.location.pathname) {
            window.location.reload();
        }
    });
}

I assume this doesn't work for CSS either though (CSS changes cause full reloads), but that's not a problem for us since we're using Tailwind, so actual CSS changes are minimal.

from inertia-laravel.

jpmaga avatar jpmaga commented on July 19, 2024 2

I got HMR working with Inertia in most cases. There's one issue where there's odd behaviour when a hot reload happens after you've navigated with Inertia, but I solved that by doing a full refresh in those cases.

I'm not using Laravel Mix, but my webpack is set up to mirror Mix as much as possible, so I don't think it really matters much. However this is without BrowserSync.

I added this to my main app.js file and it seems to work:

if (module.hot) {
    const firstVisit = window.location.pathname;

    module.hot.accept();

    module.hot.dispose(() => {
        if (firstVisit !== window.location.pathname) {
            window.location.reload();
        }
    });
}

I assume this doesn't work for CSS either though (CSS changes cause full reloads), but that's not a problem for us since we're using Tailwind, so actual CSS changes are minimal.

I feel like this could very well be in the documentation somewhere. Thanks for the snippet, btw.

from inertia-laravel.

nckrtl avatar nckrtl commented on July 19, 2024 1

Thx for your replies. @sebastiandedeyne your snippet doesn't seem to work for me. I alternatively got it working with mix like this:

const cssImport = require('postcss-import')
const cssNesting = require('postcss-nesting')
const mix = require('laravel-mix')
const path = require('path')
const tailwindcss = require('tailwindcss')

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.options({
  hmrOptions: {
    host: 'pingcrm.test',  // site's host name
  }
});

mix.js('resources/js/app.js', 'public/js')
  .postCss('resources/css/app.css', 'public/css', [
    cssImport(),
    cssNesting(),
    tailwindcss('tailwind.js'),
  ])
  .webpackConfig({
    output: { chunkFilename: 'js/[name].[contenthash].js' },
    resolve: {
      alias: {
        'vue$': 'vue/dist/vue.runtime.js',
        '@': path.resolve('resources/js'),
      },
    },
    devServer: {
      proxy: {
        host: '0.0.0.0',  // host machine ip
        port: 8080,
      },
      watchOptions:{
        aggregateTimeout:200,
        poll:5000
      },
    },
  })
  .version()
  .sourceMaps()

With adding (tailwind) classes / inline styling for development is actually working pretty well. It was something I haven't thought about yet. It's also pushing me to use tailwind more, which I like. Thx!

from inertia-laravel.

reinink avatar reinink commented on July 19, 2024

Pinging @sebastiandedeyne. I know he's done some work to get hot reloading working that might be related to this.

from inertia-laravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.