SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.2k stars 662 forks source link

Add Tutorial/Option to Live Reload when Developing React Components #1216

Open wdfinch opened 2 years ago

wdfinch commented 2 years ago

Describe the problem feature solves When developing custom React components in adminjs applications, I constantly need to refresh the browser to see my changes. It would be nice if there were some way to easily configure live reloading or some tutorial.

Describe the solution you'd like Documentation or config options to enable live reloading.

Describe alternatives you've considered Refreshing the browser on every code change.

Acceptance criteria NA

dziraf commented 2 years ago

@wdfinch by live reloading do you mean some kind of websocket implementation that automatically shows new changes when creating/updating/deleteing records or just a button which reloads contents without refreshing the browser?

wdfinch commented 2 years ago

Thanks for the reply! Sorry I wasn't very clear. I've updated the title and details above. I was referring to adding a live reload feature when developing custom react components. When adding these components, I need to refresh the browser every time I make changes (I have nodemon restarting the server). It would be nice if the browser could just refresh on its own when I make a change.

Hot Module Replacement (HMR) would also solve this problem but might be harder to implement.

markstreich commented 1 year ago

This works for me:

npm install livereload

const admin = new AdminJS(
...
    assets: {
      scripts:
        process.env.NODE_ENV !== 'production'
          ? [`http://localhost:35729/livereload.js?snipver=1`]
          : [],
    },
)

....

  if (process.env.NODE_ENV === 'production') {
    await admin.initialize();
  } else {
    admin.watch();
    var server = livereload.createServer();
    server.watch(path.join(__dirname, '/.adminjs'));
  }