vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

unable to use assets with space in name

Open jinlianglou opened this issue 3 years ago • 2 comments

Describe the bug

当xxx.md中引用了图片,而图片的名字中含有空格则build失败 如图: WX20220308-210322@2x

图片名字如下: Screenshot 2021-07-05 at 12.53.29.png

在xxx.md中去掉相关以下内容 build 成功。 ![Screenshot 2021-07-05 at 12.53.29.png](gettingstande.assets/Screenshot%202021-07-05%20at%2012.53.29.png)

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.

jinlianglou avatar Mar 08 '22 13:03 jinlianglou

Most likely, this won't be fixed anytime soon. Similar issues are open in VuePress for over 2 years.

brc-dd avatar May 29 '22 15:05 brc-dd

I guess this is the current limitation in Vite? Found this issue. https://github.com/vitejs/vite-plugin-vue/issues/218.

kiaking avatar May 30 '22 06:05 kiaking

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 ?

Jeff-Tian avatar Jul 09 '23 11:07 Jeff-Tian

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:

  1. Create a postinstall.js file 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!');
    });
});

  1. Add a line to package.json's scripts:
+     "postinstall": "node postinstall.js"

Jeff-Tian avatar Jul 11 '23 01:07 Jeff-Tian