<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                # 構建&部署 [TOC] ## 構建 項目開發完成之后,執行以下命令進行構建 ```bash yarn build ``` 構建打包成功之后,會在根目錄生成 dist 文件夾,里面就是構建打包好的文件 ### 舊版瀏覽器兼容 在 **.env.production** 內 設置 `VITE_LEGACY=true` 即可打包出兼容舊版瀏覽器的代碼 ```bash VITE_LEGACY = true ``` ### 預覽 發布之前可以在本地進行預覽,有多種方式,這里介紹兩種 **不能直接打開構建后的 html 文件** - 使用項目自定的命令進行預覽(推薦) ```bash # 先打包在進行預覽 yarn preview # 直接預覽本地 dist 文件目錄 yarn preview:dist ``` - 本地服務器預覽(通過 live-server) ```bash # 1.全局安裝live-server yarn global add live-server # 2. 進入打包的后目錄 cd ./dist # 本地預覽,默認端口8080 live-server # 指定端口 live-server --port 9000 ``` ### 分析構建文件體積 如果你的構建文件很大,可以通過項目內置 [rollup-plugin-analyzer](https://github.com/doesdev/rollup-plugin-analyzer) 插件進行代碼體積分析,從而優化你的代碼。 ```bash yarn report ``` 運行之后,在自動打開的頁面可以看到具體的體積分布,以分析哪些依賴有問題。 >[info] >左上角可以切換 顯示 gzip 或者 brotli ![](https://img.kancloud.cn/d1/a2/d1a269645f10e57fbaa96554cef2914f_3170x1812.png) ## 壓縮 ### 開啟 gzip 壓縮 開啟 gzip,并配合 nginx 的 `gzip_static` 功能可以大大加快頁面訪問速度 >[info] >只需開啟 `VITE_BUILD_COMPRESS='gzip'` 即可在打包的同時生成 .gz 文件 ```bash # 根據自己路徑來配置更改 # 例如部署在nginx /next/路徑下 則VITE_PUBLIC_PATH=/next/ VITE_PUBLIC_PATH=/ ``` ### 開啟 brotli 壓縮 brotli 是比 gzip 壓縮率更高的算法,可以與 gzip 共存不會沖突,需要 nginx 安裝指定模塊并開啟即可。 >[info] >只需開啟 `VITE_BUILD_COMPRESS='brotli'` 即可在打包的同時生成 .br 文件 ```bash # 根據自己路徑來配置更改 # 例如部署在nginx /next/路徑下 則VITE_PUBLIC_PATH=/next/ VITE_PUBLIC_PATH=/ ``` ### 同時開啟 gzip 與 brotli 只需開啟 `VITE_BUILD_COMPRESS='brotli,gzip'` 即可在打包的同時生成 `.gz` 和 `.br` 文件。 ### gzip 與 brotli 在 nginx 內的配置 ```bash http { # 開啟gzip gzip on; # 開啟gzip_static # gzip_static 開啟后可能會報錯,需要安裝相應的模塊, 具體安裝方式可以自行查詢 # 只有這個開啟,vue文件打包的.gz文件才會有效果,否則不需要開啟gzip進行打包 gzip_static on; gzip_proxied any; gzip_min_length 1k; gzip_buffers 4 16k; #如果nginx中使用了多層代理 必須設置這個才可以開啟gzip。 gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary off; gzip_disable "MSIE [1-6]\."; # 開啟 brotli壓縮 # 需要安裝對應的nginx模塊,具體安裝方式可以自行查詢 # 可以與gzip共存不會沖突 brotli on; brotli_comp_level 6; brotli_buffers 16 8k; brotli_min_length 20; brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml; } ``` ## 部署 >[warning] >項目默認是在生產環境開啟 Mock,這樣做非常不好,只是為了演示環境有數據,不建議在生產環境使用 Mock,而應該使用真實的后臺接口,并將 Mock 關閉。 ### 發布 簡單的部署只需要將最終生成的靜態文件,dist 文件夾的靜態文件發布到你的 cdn 或者靜態服務器即可,需要注意的是其中的 index.html 通常會是你后臺服務的入口頁面,在確定了 js 和 css 的靜態之后可能需要改變頁面的引入路徑。 例如上傳到 nginx `/srv/www/project/index.html` ```bash # nginx配置 location / { # 不緩存html,防止程序更新后緩存繼續生效 if ($request_filename ~* .*\.(?:htm|html)$) { add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate"; access_log on; } # 這里是vue打包文件dist內的文件的存放路徑 root /srv/www/project/; index index.html index.htm; } ``` **部署時可能會發現資源路徑不對,只需要修改`.env.production`文件即可。** ```bash # 根據自己路徑來配置更改 # 注意需要以 / 開頭和結尾 VITE_PUBLIC_PATH=/ VITE_PUBLIC_PATH=/xxx/ ``` ### 前端路由與服務端的結合 項目前端路由使用的是 vue-router,所以你可以選擇兩種方式:history 和 hash。 - **hash** 默認會在 url 后面拼接`#` - **history** 則不會,不過 `history` 需要服務器配合 可在 [src/router/index.ts](https://github.com/anncwb/vue-vben-admin/tree/main/src/router/index.ts) 內進行 mode 修改 ```ts import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'; createRouter({ history: createWebHashHistory(), // or history: createWebHistory(), }); ``` ### history 路由模式下服務端配置 開啟 history 模式需要服務器配置,更多的服務器配置詳情可以看 [history-mode](https://next.router.vuejs.org/guide/essentials/history-mode.html#html5-mode) 這里以 nginx 配置為例 **部署到根目錄** ```bash server { listen 80; location / { # 用于配合 History 使用 try_files $uri $uri/ /index.html; } } ``` **部署到非根目錄** 1. 首先需要在打包的時候更改配置 ```bash # 在.env.production內,配置子目錄路徑 VITE_PUBLIC_PATH = /sub/ ``` ```bash server { listen 80; server_name localhost; location /sub/ { # 這里是vue打包文件dist內的文件的存放路徑 alias /srv/www/project/; index index.html index.htm; try_files $uri $uri/ /sub/index.html; } } ``` ### 使用 nginx 處理跨域 使用 nginx 處理項目部署后的跨域問題 1. 配置后臺接口地址 ```bash # 在.env.production內,配置接口地址 VITE_GLOB_API_URL=/jeecgboot VITE_GLOB_DOMAIN_URL=http://localhost:8080/jeecg-boot ``` 發布模式直接修改` _app.config.js` 參考示例: ``` window.__PRODUCTION__JEECGBOOTADMIN__CONF__= {"VITE_GLOB_APP_TITLE":"JeecgBoot企業級低代碼平臺", "VITE_GLOB_APP_SHORT_NAME":"JeecgBootAdmin", "VITE_GLOB_APP_OPEN_SSO":"false", "VITE_GLOB_ONLINE_VIEW_URL":"http://fileview.jeecg.com/onlinePreview", "VITE_GLOB_DOMAIN_URL":"http://api3.boot.jeecg.com", "VITE_GLOB_API_URL":"/jeecgboot", "VITE_GLOB_API_URL_PREFIX":""}; Object.freeze(window.__PRODUCTION__JEECGBOOTADMIN__CONF__);Object.defineProperty(window,"__PRODUCTION__JEECGBOOTADMIN__CONF__",{configurable:false,writable:false,}); ``` 2. 在 nginx 配置請求轉發到后臺 ```bash server { listen 8080; server_name localhost; # 接口代理,用于解決跨域問題 location /jeecgboot{ proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 后臺接口地址 proxy_pass http://127.0.0.1:8080/jeecg-boot; proxy_redirect default; add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看