web-infra-dev / rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.
https://rsbuild.dev/
MIT License
1.35k stars 110 forks source link

[Feature]: Request to support renderBuiltUrl like vite #2741

Open zydmayday opened 2 months ago

zydmayday commented 2 months ago

What problem does this feature solve?

We are currently using vite and have this config in our app. refer doc: https://vitejs.dev/guide/build.html#advanced-base-options -> experimental.renderBuiltUrl

I searched in doc and there is no renderBuiltUrlin rebuild. So even I followed the migration doc(https://rsbuild.dev/guide/migration/vite) and finished most of them, finally I stucked with "experimental.renderBuiltUrl".

So I wonder if rsbuild is going to support this feature or not, or if you have any alternatives to this. Thanks!

// some sample code
// in our vite.config.js
experimental: {
  renderBuildUrl(filename, { hostType }) {
    if (['css', 'js'].includes(hostType)) {
      return {runtime: window.__getFile(filename)}
    }
    return {relative: true}
  }
}
// in our index.html
<script>
  window.__getFile = function (file) {
    return `${window.OTHERS.PREFIX}/${file}`;
  }
</script>

What does the proposed API look like?

I would like to have the same feature with what vite currently has. Or if you can design with a better way.

vite doc to refer: https://vitejs.dev/guide/build.html#advanced-base-options

Let me know if you need more information.

chenjiahan commented 2 months ago

Rsbuild should provide an alternative feature for this, we will try to design and implement it.