You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue+Django部署Heroku后Vue静态文件请求路径错误问题

Vue + Django 部署Heroku后静态文件路径异常问题

问题表现

本地开发环境一切正常,部署到Heroku后:

  • Django模板及应用主体能正常加载
  • Vue相关静态文件请求路径错误,控制台输出以下报错:
GET https://brainteasers.herokuapp.com/wordle-game/static/dist/js/chunk-vendors.58fb68d0.js net::ERR_ABORTED 404 (Not Found)
Refused to execute script from 'https://brainteasers.herokuapp.com/wordle-game/static/dist/js/chunk-vendors.58fb68d0.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
  • 无Vue Router路由的页面(如contact-us)静态文件请求路径正确,示例:https://brainteasers.herokuapp.com/static/js/home-styles.js;但带有独立URL的Vue SPA页面(如wordle-game),静态文件请求路径错误地包含了路由前缀,变成https://brainteasers.herokuapp.com/wordle-game/static/dist/js/chunk-vendors.58fb68d0.js,导致404。

项目目录结构

static (backend)
├── css
├── dist (vue build产物目录)
│   ├── css
│   └── js
└── img

当前vue.config.js配置

module.exports = {
  publicPath: 'static/dist/', // 期望拼接在顶级域名后的基础URL
  outputDir: '../static/dist', // Vue构建文件输出到Django的static/dist目录
  indexPath: '../../templates/_base_vue.html', // 生成的index文件路径

  configureWebpack: {
    devServer: {
      devMiddleware: {
        writeToDisk: true
      }
    }
  }
};

核心困惑

Vue Router的路由设置干扰了静态文件的请求路径——路由前缀被错误地加到了静态文件URL中。目前卡在如何通过配置区分Django模板的查找路径和Vue静态文件的存储路径,避免静态文件请求被路由路径影响。


内容的提问来源于stack exchange,提问作者Ubuntufoo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 09:45:32