`base` option does not support external URLs with the development server
See original GitHub issue⚠️ 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.
- 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
- 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
},
// ...
})
- Compare the URL of the Vue logo in the inspector window between content served via
npm run dev
andnpm run build && npm run serve
. Thesrc
attribute of the<img>
tag will only contain the base ofhttp://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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:13 (5 by maintainers)
Don’t want to be pushy but could we at least reopen this issue? I’m trying to get Vite working with Craft, too, and this is the biggest blocker right now.
Agree, would love to see this re-opened, I referenced it here: https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms#vite-processed-assets
…and it is still an issue, at least imo.