当存储在公用文件夹中时,我的图像资源将在生产环境中显示如下:
https://ip/static/img/xxx.png但是,我希望是这样:
https://ip/xxx/xxx/xxx/static/img/xxx.png, 因为
https://ip/xxx/xxx/xxx/index.html 这是我的项目之路;
有人能告诉我怎么设置这个吗?
当我将静态资源存储在另一个文件夹(例如,“静态”文件夹)中时,它将在我构建项目之后显示在正确的路径中,因为我使用了相对路径。
../../static/img/xxx.png这是我在vite.config.js中的设置
此外,当我使用别名命名时,我无法导入其他资源,
const test = "*/xxx/xxx.png";它显示:
https://ip//*/xxx/xxx.pngvue2.6.14,ve2.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",
},
});谢谢你一百万。
发布于 2021-10-20 10:07:37
此外,当我使用别名命名时,我无法导入其他资源,
const test = "*/xxx/xxx.png";
它显示:
https://ip//*/xxx/xxx.png
用途:import test from "*/logo.png";
更多信息:https://vitejs.dev/guide/assets.html#static-asset-handling
https://stackoverflow.com/questions/69643027
复制相似问题