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]: unocss rspack plugin hmr not work #4615

Open
me9rez opened this issue Feb 20, 2025 · 3 comments
Open

[Bug]: unocss rspack plugin hmr not work #4615

me9rez opened this issue Feb 20, 2025 · 3 comments

Comments

@me9rez
Copy link

me9rez commented Feb 20, 2025

Version

System:
    OS: Windows 11 10.0.26100
    CPU: (12) x64 AMD Ryzen 5 5600 6-Core Processor              
    Memory: 16.93 GB / 31.95 GB
  Browsers:
    Edge: Chromium (132.0.2957.140)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    @rsbuild/core: ^1.2.11 => 1.2.11 
    @rsbuild/plugin-vue: ^1.0.6 => 1.0.6

Details

根据官网, 配置rsbuild和unocs环境,pnpm dev启动开发服务器, 修改class,发现页面无法热更新,必须刷新页面后才能看到样式修改效果。(使用postcss模式hmr正常工作)

Reproduce link

https://github.com/me9rez/rsbuild-unocss-hmr-issue

Reproduce Steps

复现步骤:

  1. pnpm i
  2. pnpm dev
  3. 修复App.vue中的class, 发现hmr功能无效
@chenjiahan
Copy link
Member

I think this is a issue with the unocss implementation.

According to the unocss documentation, you have to disable the cache to make HMR work, but this will increase the HMR time:

export default defineConfig({
  tools: {
    rspack: {
      cache: false,
    },
  },
});

Related documentation:

@xbzhang2020
Copy link
Contributor

Maybe using @unocss/postcss is better than using @unocss/webpack/rspack in Rsbuild currently. Here are some problems I encountered.

First, HMR in the unocss postcss plugin works well and quickly. However, the unocss rspack plugin is not so good.

Second, if you use the unocss rspack plugin, @apply, @screen, and theme() directives, which are powered by @unocss/transformer-directives, are unsupported because @unocss/transformer-directives will be ignored in webpack/rspack. However, the uncoss postcss plugin supports these directives.

Related:
https://unocss.dev/integrations/postcss
https://github.com/unocss/unocss/blob/main/packages-integrations/webpack/src/unplugin.ts#L97

@chenjiahan chenjiahan reopened this Feb 22, 2025
@me9rez
Copy link
Author

me9rez commented Feb 23, 2025

Maybe using @unocss/postcss is better than using @unocss/webpack/rspack in Rsbuild currently. Here are some problems I encountered.

First, HMR in the unocss postcss plugin works well and quickly. However, the unocss rspack plugin is not so good.

Second, if you use the unocss rspack plugin, @apply, @screen, and theme() directives, which are powered by @unocss/transformer-directives, are unsupported because @unocss/transformer-directives will be ignored in webpack/rspack. However, the uncoss postcss plugin supports these directives.

Related: https://unocss.dev/integrations/postcss https://github.com/unocss/unocss/blob/main/packages-integrations/webpack/src/unplugin.ts#L97

Hello, thank you so much for reporting the issues you encountered when using the relevant plugins in Rsbuild. Your analysis is really clear - cut! The differences in HMR and the problems regarding directive support can significantly affect the development experience. The related links you provided are also of great value. We'll look into them carefully and troubleshoot and fix these issues as soon as possible.
Thanks again for your sharing and support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants