Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] after setting base, vite failed to handle assets with absolute paths in dev mode #1442

Closed
WangJincheng4869 opened this issue Dec 1, 2023 · 9 comments
Labels
bug Something isn't working package:bundler-vite

Comments

@WangJincheng4869
Copy link

Description

当配置 base 后不会处理图片地址,导致图片无法显示

image

Reproduction

https://stackblitz.com/edit/vuepress-theme-hope-4jgewz?file=docs%2Fdemo%2FREADME.md,docs%2F.vuepress%2Fclient.ts,docs%2F.vuepress%2Fconfig.ts

Used Package Manager

pnpm

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 14.43 GB / 31.56 GB
  Binaries:
    Node: 20.9.0 - D:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 9.2.0 - D:\Users\jcwang\AppData\Roaming\npm\npm.CMD
  Utilities:
    Git: 2.43.0.
  Browsers:
    Chrome: Not Found
    Edge: Chromium (119.0.2151.72)
  npmPackages:
    @vuepress/bundler-vite: 2.0.0-rc.0 => 2.0.0-rc.0
    @vuepress/bundler-webpack: Not Found
    @vuepress/cli: Not Found
    @vuepress/client: 2.0.0-rc.0 => 2.0.0-rc.0
    @vuepress/core: Not Found
    @vuepress/markdown: Not Found
    @vuepress/plugin-active-header-links: Not Found
    @vuepress/plugin-back-to-top: Not Found
    @vuepress/plugin-container: Not Found
    @vuepress/plugin-docsearch: Not Found
    @vuepress/plugin-external-link-icon: Not Found
    @vuepress/plugin-git: Not Found
    @vuepress/plugin-google-analytics: Not Found
    @vuepress/plugin-medium-zoom: Not Found
    @vuepress/plugin-nprogress: Not Found
    @vuepress/plugin-palette: Not Found
    @vuepress/plugin-prismjs: Not Found
    @vuepress/plugin-pwa: Not Found
    @vuepress/plugin-pwa-popup: Not Found
    @vuepress/plugin-register-components: 2.0.0-rc.0 => 2.0.0-rc.0
    @vuepress/plugin-search: Not Found
    @vuepress/plugin-shiki: Not Found
    @vuepress/plugin-theme-data: Not Found
    @vuepress/plugin-toc: Not Found
    @vuepress/shared: Not Found
    @vuepress/theme-default: Not Found
    @vuepress/utils: Not Found
    vue: ^3.3.9 => 3.3.9
    vue-loader: Not Found
    vue-router: ^4.2.5 => 4.2.5
    vuepress: 2.0.0-rc.0 => 2.0.0-rc.0
    vuepress-vite: Not Found
    vuepress-webpack: Not Found
@Mister-Hope Mister-Hope added the bug Something isn't working label Dec 1, 2023
@Mister-Hope
Copy link
Member

Mister-Hope commented Dec 1, 2023

cc @meteorlxy A real repro here: https://stackblitz.com/edit/vuepress-theme-hope-pbl7xt?file=package.json,README.md

Seems to be a serious bug.

From our docs, the base should be appended.

@WangJincheng4869
Copy link
Author

WangJincheng4869 commented Dec 6, 2023

这个问题降级 vuepress 是没有用的,只能降级 vite 到 4 ,无法使用 vite 5

使用 vite 4 时,虽然没有在图片 src 中添加 base,但是可以正常显示图片
1$X{41GJ7SHQ%~ {AX310WQ

使用 vite 5,图片中的 src 也没有添加 base,就无法显示图片
H)I6~G9Q~KIPH4XTDMBIP

@Mister-Hope
Copy link
Member

Can you provide details with production? The above information is devServer.

@WangJincheng4869
Copy link
Author

Can you provide details with production? The above information is devServer.

我将你的复现换成了 vite4,图片可以正常显示了 https://stackblitz.com/edit/vuepress-theme-hope-umxnhe?file=package.json,docs%2FREADME.md

image

@WangJincheng4869
Copy link
Author

经过测试 build 后的结果是正常的,添加上了 base,这个问题只是在 dev 环境下存在

@Mister-Hope
Copy link
Member

cc @meteorlxy

@XiSenao
Copy link

XiSenao commented Dec 19, 2023

The parsing template is not provided to Vite for parsing, and the processing process of Vite should be as expected. It seems that markdown-it does not support base URL, so I think it may be more appropriate to implement a similar plugin for markdown-it.

@meteorlxy
Copy link
Member

Maybe we can port the fix vuejs/vitepress#3239

@meteorlxy meteorlxy changed the title [Bug report] 设置 base 后不会处理图片 [Bug report] after setting base, vite failed to handle assets with absolute paths in dev mode Dec 20, 2023
@meteorlxy
Copy link
Member

meteorlxy commented Dec 20, 2023

The current fix only works on vite. A better solution might be a markdown-it plugin as @XiSenao proposed.

--- update

For webpack, you can enable markdown.assets.absolutePathPrependBase to handle image base automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:bundler-vite
Projects
None yet
Development

No branches or pull requests

4 participants