[Vuejs]-Vue project(vue-cli 3/4) lazy loading route can not reach static file when I host static files on CDN

0👍

There’s two things to do here…

  1. Set your publicPath to the static site base URL

    // vue.config.js
    module.exports = {
      publicPath: process.env.NODE_ENV === "production"
        ? "https://static.my-site.com/"
        : "/"
    }
    
  2. Set your router’s base to the base path of your app

    import Vue from "vue"
    import VueRouter from "vue-router"
    
    Vue.use(VueRouter)
    
    const router = new VueRouter({
      base: process.env.NODE_ENV === "production"
        ? "/my-path/"
        : "/",
      routes: [...]
    })
    

-1👍

You could use the absolute locations in the import statements

Leave a comment