Skip to content

base option does not support external URLs with the development server #2196

@SirDavidLudwig

Description

@SirDavidLudwig

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

The base option currently does not support the ability to specify external URLs when serving content through the development server. This greatly limits the incorporation of Vite into other backends (Laravel, etc.) as static assets can no longer be served since the assets are served on a different port than the web server. I explored this specific problem in more depth in a separate issue by attempting to integrate Vite into a Laravel project.

As a solution suggestion, I believe that this issue would be solved best by implementing an environment variable to specify a URL base for content served specifically through the dev server. This would resolve these issues with backend compatibility and allow for the most flexability in users' dev environments.

Reproduction

I'm not sure how worthwhile a reproduction guide is for this issue, but this should give you something to compare against.

  1. Create a vue-ts project using the @vitejs/app init script
npm init @vitejs/app
    # Project name: vite-static-assets
    # Select a template: vue-ts
cd vite-static-assets
npm install
  1. Set base property in vite.config.ts:
export default defineConfig({
  base: "http://localhost:3000/",
  server: {
    port: 3000 // Use the same port for dev and serve
  },
  // ...
})
  1. Compare the URL of the Vue logo in the inspector window between content served via npm run dev and npm run build && npm run serve. The src attribute of the <img> tag will only contain the base of http://localhost:3000/ on production builds.

System Info

  • vite version: 2.0.1
  • Operating System: Ubuntu 20.10
  • Node version: 14.15.4
  • Package manager (npm/yarn/pnpm) and version: npm

Logs (Optional if provided reproduction)

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions