V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
SystemLight
V2EX  ›  Vue.js

vue.config.js 如何配置生成的 HTML 文件种静态资源引入路径?

  •  
  •   SystemLight ·
    SystemLight · Jun 26, 2021 · 2407 views
    This topic created in 1773 days ago, the information mentioned may be changed or developed.
      1. vue.config.js 似乎只可以配置 publicPath,但是这个参数不仅改变了 HTML 文件中静态文件引入路径,同时改变了程序中 vueRouter 的路径
      1. 通过 webpackCahin 配置 HTMLPlugin 的 publicPath 参数无效,仍然会按照上层 publicPath 生成
    module.exports = {
        publicPath: "/",
        chainWebpack: (config) => {
            config
                .plugin("html")
                .tap((args) => {
                    args[0].title = "课程管理";
                    args[0].publicPath = "/static";
                    return args;
                });
        },
        devServer: {
            proxy: 'http://localhost:5500'
        }
    }
    
    
    2 replies    2021-06-27 15:27:13 +08:00
    IndexXuan
        1
    IndexXuan  
       Jun 27, 2021 via iPhone
    你把生成的项目里 router.js 里的 base 改下,不接收 process.env.BASE_URL 不就行了,脑袋灵活些啊
    SystemLight
        2
    SystemLight  
    OP
       Jun 27, 2021
    @IndexXuan 非常感谢,之前看了好几遍 vue-router 的文档,真正实用的时候还是没有想到,属实是缺少经验
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2897 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 06:28 · PVG 14:28 · LAX 23:28 · JFK 02:28
    ♥ Do have faith in what you're doing.