How to get the right static resource path in production environment when using vite?

Viewed 789

When stored in the public folder, my image resources will show in production environment as follow:

https://ip/static/img/xxx.png

But, I want it to be like this:

https://ip/xxx/xxx/xxx/static/img/xxx.png, 

Because

https://ip/xxx/xxx/xxx/index.html 

Which is my project path;

Could anyone tell me how to set this?

When I stored the static resource in another folder, for example, the "static" folder, it will show in the right path after I built the project because I used the relative path

../../static/img/xxx.png

This is my setting in vite.config.js

Besides, I can't import another resource when I used alias naming,


const test = "*/xxx/xxx.png";

It shows:

https://ip//*/xxx/xxx.png

vue2.6.14, vite2.5.1

import { defineConfig } from "vite";
import { createVuePlugin } from "vite-plugin-vue2";
import ViteComponents from "vite-plugin-components";
import { join } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  base: "",
  resolve: {
    alias: {
      "@": join(__dirname, "src"),
      "~": join(__dirname, "src/components"),
      "*": join(__dirname, "static/img"),
    },
    extensions: [".js", ".vue", ".json", ".mjs"],
  },
  plugins: [createVuePlugin(), ViteComponents()],
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: '@import "./src/less/varsbank.module.less";',
      },
    },
  },
  optimizeDeps: {
    include: ["axios"],
  },
  server: {
    port: 8080,
  },
  build: {
    assetsDir: "static",
  },
});

Thanks a million.

1 Answers
Related