国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vite + Vue3 + Ts 解決打包生成的index.html頁面顯示空白、資源跨域、找不到資源、404-Page Not Found等錯(cuò)誤;關(guān)于vite build后訪問報(bào)錯(cuò) 關(guān)于vite build后訪問報(bào)錯(cuò):Expected a JavaScript module script but the server responded with a MIME type of “

這篇具有很好參考價(jià)值的文章主要介紹了Vite + Vue3 + Ts 解決打包生成的index.html頁面顯示空白、資源跨域、找不到資源、404-Page Not Found等錯(cuò)誤;關(guān)于vite build后訪問報(bào)錯(cuò) 關(guān)于vite build后訪問報(bào)錯(cuò):Expected a JavaScript module script but the server responded with a MIME type of “。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一.vite.config.ts配置:主要的就是base: env.VITE_MODE === 'production' ? './' : '/',

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue';
import path from "path";
import { resolve } from 'path'
const port = 8080;
const host = "0.0.0.0";
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, __dirname)
  return {
    plugins: [
      vue(),
    ],
    base: env.VITE_MODE === 'production' ? './' : '/',
    resolve: {
      alias: {
        //resolve.alias設(shè)置別稱 解決@絕對路徑引入問題
        "@": path.resolve(__dirname, 'src'),
        "@assets": path.resolve(__dirname, "src/assets"),
        "@components": path.resolve(__dirname, "src/components"),
        "@images": path.resolve(__dirname, "src/assets/images"),
        "@views": path.resolve(__dirname, "src/views"),
        "@store": path.resolve(__dirname, "src/store"),
      },
    },
    css: {
      // css預(yù)處理器
      preprocessorOptions: {
        less: {
          modifyVars: {
            // 全局less變量存儲(chǔ)路徑(配置less的全局變量)
            hack: `true; @import (reference) "${resolve('src/public/config.less')}";`,
          },
          javascriptEnabled: true,
        }
      }
    },
    build: {
      outDir: "dist",
      assetsDir: "assets", //指定靜態(tài)資源存放路徑
      sourcemap: false, //是否構(gòu)建source map 文件
      // terserOptions: {
      //   // 生產(chǎn)環(huán)境移除console
      //   compress: {
      //     drop_console: true,
      //     drop_debugger: true,
      //   },
      // },
    },
    server: {
      https: false, // 是否開啟 https
      open: true, // 是否自動(dòng)在瀏覽器打開
      port: port, // 端口號(hào)
      host: host,
      proxy: {
        "/api": {
          target: env.VITE_RES_URL, // 后臺(tái)接口
          changeOrigin: true,
          secure: false, // 如果是https接口,需要配置這個(gè)參數(shù)
          ws: true, //websocket支持
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
  }
})

二. 打包后的結(jié)果如圖所示,文件路徑是./ 其實(shí) 去掉./是可以的,但是打包后是/favicon.ico這種路徑是訪問不到的,參考第一部分

vite打包后直接打開html 空白,vite,前端,開發(fā)語言,vue.js,html

三. 配置路由:路由改成?createWebHashHistory?

vite打包后直接打開html 空白,vite,前端,開發(fā)語言,vue.js,html

?四. vscode安裝Live Server?

vite打包后直接打開html 空白,vite,前端,開發(fā)語言,vue.js,html

?vite打包后直接打開html 空白,vite,前端,開發(fā)語言,vue.js,html

關(guān)于vite build后訪問報(bào)錯(cuò):Expected a JavaScript module script but the server responded with a MIME type of “

vite打包后直接打開html 空白,vite,前端,開發(fā)語言,vue.js,html

部署到線上時(shí),頁面一刷新就會(huì)報(bào)上述錯(cuò)誤,百度了半天也沒解決,參考了這個(gè)大佬的文章,寫的很詳細(xì),跟著步驟做也是可以解決報(bào)錯(cuò)的!

下面說一下我的解決方式 :

?1. base 設(shè)置成 './'? ?

vite打包后直接打開html 空白,vite,前端,開發(fā)語言,vue.js,html

?2. 路由模式改成 createWebHashHistory即可

vite打包后直接打開html 空白,vite,前端,開發(fā)語言,vue.js,html

?Tips:參考了好多大佬寫的,有的把base './'? 改成 '/'的 不過我改成 '/' 資源路徑不對還是白屏,跟著配置一圈沒解決,無意中把路由模式 createWebHistory 改成?createWebHashHistory 就解決了問題!白屏也跟Nginx有關(guān)。歡迎各位大佬批評指正與補(bǔ)充!文章來源地址http://www.zghlxwxcb.cn/news/detail-665802.html

到了這里,關(guān)于Vite + Vue3 + Ts 解決打包生成的index.html頁面顯示空白、資源跨域、找不到資源、404-Page Not Found等錯(cuò)誤;關(guān)于vite build后訪問報(bào)錯(cuò) 關(guān)于vite build后訪問報(bào)錯(cuò):Expected a JavaScript module script but the server responded with a MIME type of “的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包