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]: static resource can not resolve from public path in css file. #3429

Closed
jackchoumine opened this issue Sep 10, 2024 · 2 comments
Closed
Labels
🐞 bug Something isn't working

Comments

@jackchoumine
Copy link

jackchoumine commented Sep 10, 2024

Version

version info:

"@rsbuild/core": "^1.0.1-rc.5",

Details

There are some img in public:

public/imgs/wms-0-params.png

use it in vue3 component:

<template>
  <div class="main-wrapper flex flex-1 flex-col">
    <p>hello world</p>
    <!-- NOTE  work well -->
    <img src="/imgs/wms-0-params.png" alt="" srcset="" />
  </div>
</template>

<style lang="scss" scoped>
p {
  color: red;
  /* NOTE can not work Error: HookWebpackError: Cannot find module '/imgs/wms-0-params.png' */
  background-image: url('/imgs/wms-0-params.png');
}
</style>

in css part, it can not reslove img path:

Error: HookWebpackError: Cannot find module '/imgs/wms-0-params.png'

rsbuild/core@^0.4.6 work well

Related issue: #3374

Someone say put img into src/assets path then use img by relative path. It is not good migration way.

It is a barrier for migration from vite.

Reproduce link

Reproduce Steps

@jackchoumine jackchoumine added the 🐞 bug Something isn't working label Sep 10, 2024
@liu-collab
Copy link

you can do this

tools: {
      cssLoader: { url: { filter: (url) => !url.includes('imgs') } },
    },

@jackchoumine jackchoumine changed the title [Bug]: static resource can not resolve from plublic path in css file. [Bug]: static resource can not resolve from public path in css file. Sep 10, 2024
@9aoy
Copy link
Collaborator

9aoy commented Sep 10, 2024

Rsbuild uses css-loader by default to handle CSS resources.You can use the cssLoader.url option to filter the public resource path like the example above.

If you use experiments.css, you can use rspack.IgnorePlugin to ignore public resources path. webpack/webpack#14893 (comment)

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

No branches or pull requests

3 participants