Skip to content

Cannot exclude public assets #4991

@everdrone

Description

@everdrone

Describe the bug

I am deploying a vitepress app with cloudflare workers and the images will be hosted on cloudflare R2.
I tried adding this to the config

  vite: {
    build: {
      rollupOptions: {
        external: /^\/media\//,
      },
    },
  },

to exclude all paths starting with /media/.

But in a test page containing

![alt](/media/remote-image.png)

The build fails trying to process the asset:

✖ rendering pages...
build error:
Cannot find module '/media/remote-image.png'

Reproduction

add an image ![alt](/media/remote-image.png) and mark all imports starting with /media/ as external:

export default defineConfig({
  vite: {
    build: {
      rollupOptions: {
        external: /^\/media\//,
      },
    },
  },
});

Expected behavior

All excluded assets will be ignored during the build process and included as plain urls.

<img alt="alt" src="/media/remote-image.png" />

System Info

System:
    OS: macOS 15.7
    CPU: (8) arm64 Apple M3
    Memory: 213.20 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.0 - /Users/everdrone/.local/state/fnm_multishells/42219_1760630691922/bin/node
    npm: 10.9.2 - /Users/everdrone/.local/state/fnm_multishells/42219_1760630691922/bin/npm
    pnpm: 10.11.1 - /Users/everdrone/Library/pnpm/pnpm
  Browsers:
    Chrome: 141.0.7390.78
    Firefox: 144.0
    Safari: 26.0.1
  npmPackages:
    vitepress: ^1.6.4 => 1.6.4

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions