vite+vue3 部署IIS服務器非根目錄


主要需要注意兩個兩個地方

1.增加一個路由base,具體根據服務器的文件夾來更改

const router = createRouter({
    history: createWebHistory("/demo/"),
    scrollBehavior: () => ({
        top: 0,
    }),
    routes: constantRoutes,
});

2.打包公共基礎路徑

我們就根據官網給出的操作來就好了,官網地址:https://vitejs.cn/guide/build.html#public-base-path

 

 所以我們打包的時候直接輸入命令,具體根據服務器的文件夾來更改

vite build --base=/demo/

3.IIS防止刷新404配置

當前項目里新建一個web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="zkpt.asmx" />
                <add value="index.html" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="iisstart.htm" />
                <add value="default.aspx" />
            </files>
        </defaultDocument>
        <!-- 刷新白屏增加配置start -->
 <rewrite>
      <rules>
        <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.html" />
        </rule>
      </rules>
    </rewrite>
    </system.webServer>
    <!-- 刷新白屏增加配置end -->
</configuration>

這樣就搞定啦~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM