1

In webpack I could do something like to this to handle some development middleware code, which includes doing some work/testing inside the app.get call.

devServer: {
    before: function (app, server) {
        app.get ("/", function (req, resp, next) {
            // Do some stuff
            resp.redirect ("someUrl")
        }
    }
}              

It seems like Vite should have some kind of similar functionality, but I have not found the right docs yet to help me out. Does anyone have an example of this for Vite?

GoldenRam
  • 11
  • 4
  • 1
    https://vitejs.dev/guide/api-plugin.html#configureserver – Michal Levý Sep 30 '21 at 09:52
  • Well, that works with the PluginApi, are you implying I need to build my own plugin? I was hoping I could just add a small bit of code into my vite.config.ts that does similar to what I have in my webpack.config.js. I'd love to see a small example. Only thing I've found is the https://github.com/axe-me/vite-plugin-node, which appears to be configurable, but wondered if I needed it. – GoldenRam Oct 01 '21 at 21:18
  • Yes, from what I have found it seems you need to create plugin. But it is not [that hard](https://github.com/chaosprint/vite-plugin-cross-origin-isolation) – Michal Levý Oct 02 '21 at 15:04

0 Answers0