How to change vite dev server asset base path?

by cortez.connelly , in category: Javascript , 25 days ago

How to change vite dev server asset base path?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 24 days ago

@cortez.connelly 

To change the asset base path in the Vite dev server, you can use the base option in the server configuration section in the vite.config.js file.


Here's how you can do it:

  1. Open the vite.config.js file in the root of your project.
  2. Add a server section if it doesn't already exist, and set the base option to the desired asset base path. For example, if you want the assets to be served from the /assets path, you can set it like this:
1
2
3
4
5
module.exports = {
  server: {
    base: '/assets/'
  }
}


  1. Save the file.
  2. Restart the Vite dev server for the changes to take effect.


Now, when you run the dev server, your assets will be served from the specified base path. You can access them in your HTML or JavaScript files using relative paths from the base path.