vitepress
vitepress copied to clipboard
unable to use assets with space in name
Describe the bug
当xxx.md中引用了图片,而图片的名字中含有空格则build失败
如图:

图片名字如下:
Screenshot 2021-07-05 at 12.53.29.png
在xxx.md中去掉相关以下内容 build 成功。

Reproduction
yarn build:docs
Expected behavior
希望有空可以优化下。
System Info
System:
OS: macOS 12.0.1
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 16.57 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.13.1 - /usr/local/bin/node
Yarn: 1.5.1 - /usr/local/bin/yarn
npm: 8.1.2 - /usr/local/bin/npm
Browsers:
Chrome: 93.0.4577.82
Edge: 99.0.1150.36
Additional context
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Most likely, this won't be fixed anytime soon. Similar issues are open in VuePress for over 2 years.
I guess this is the current limitation in Vite? Found this issue. https://github.com/vitejs/vite-plugin-vue/issues/218.
Most likely, this won't be fixed anytime soon. Similar issues are open in VuePress for over 2 years.
https://github.com/vuejs/vuepress/issues/2152 ?
https://github.com/vuejs/core/pull/8752 might fix it.
Before the fix, there is a workaround, which works great as I've been using it for months:
- Create a
postinstall.jsfile and paste the following code:
const fs = require('fs');
const filePath = 'node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js';
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
const modifiedData = data.replace(
/context.imports\.push\(\{\s*exp,\s*path:\s*path2\s*}\);/g,
"context.imports.push({ exp, path: path2 && path2[0] === '/' ? decodeURIComponent(path2) : path2 });"
);
fs.writeFile(filePath, modifiedData, 'utf8', (err) => {
if (err) {
console.error(err);
return;
}
console.log('File modified successfully!');
});
});
- Add a line to
package.json's scripts:
+ "postinstall": "node postinstall.js"