admin管理员组文章数量:1392101
Is there a way to build a VUE 3 app once and deploy to different locations or subdirectories? For background what I'm trying to do is have an ASP.NET Core MVC app run and in one of the routes I want to have a vue app hosted inside my MVC page with the heading and nav provided by the razor layout. I've gotten most of the pieces working, but there is a final piece where something in the build is generating it's own links at run-time in the <head>
for stylesheets and modules that have incorrect paths:
<link rel="modulepreload" as="script" crossorigin="" href="/dist/assets/AboutView-DUrvszN_.js">
<link rel="stylesheet" crossorigin="" href="/assets/dist/AboutView-CSIvawM9.css">
What I currently do is build the vue project and copy the dist
folder to the wwwroot
directory. I can get this to work running locally in Visual Studio if I add a base
property to vite.config.ts
:
base: '/dist/'
When I deploy to the server however, it is in a virtual application 'VueTest' in IIS. If I change the base in vite.config.ts
to /VueTest/dist/
it works, but I don't want to have to rebuild.
Is there a way to set this at runtime? I've thought about changing that to some string like 'REPLACE_ME' and doing it at runtime. I've spent time getting other things to work. For example in my controller action I use HttpContext.Request.PathBase
for use in loading the index js and css in the razor view. I also inject IWebHostEnvironment
and use WebRootPath
to find the names with hashes for index-*.js
and index-*.css
. I also set a ViewData property and set a property on the window object in the razor view so my router can use it. This works great with createWebHashHistory and allows deep-linking into the vue app router.
I want to use the exact same build so that dev/test/and prod all use the same build and to make it easy if we want to host in a different virtual directory. It just doesn't seem like it's the build's problem where it is hosted. If I work with a version locally by debugging at https://localhost:7077/
in Visual Studio, I don't want to create three different builds because deploying to dev, test, and prod all have different paths.
(,
, and
Is there a way to accomplish what I want, or am I stuck creating different builds for each place I want to deploy to?
本文标签: vuejs3How do you change vue base path at runtimeStack Overflow
版权声明:本文标题:vuejs3 - How do you change vue base path at runtime? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744780061a2624654.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论