Plugin development: I can't get addDependency to watch and reload on file change #5935
-
I am attempting to build an Rsbuild plugin for UnoCSS. Their support for Rstack is pretty minimal, and I felt a handmade plugin would perform better than their suggested approach. UnoCSS is like Tailwind, where a virtual CSS file is generated based on tokens scanned from user source files. I am building in the Virtual Module plugin to handle this, and so far that part is working. However, another feature Uno supports is watching arbitrary files in the filesystem which are not packaged in the bundler. I am struggling to get Rsbuild/Rspack to actually monitor for changes which come from outside the bundler's source files. My plugin source is here: https://github.com/a-type/rsbuild-plugin-unocss Here is the approach I'm trying to use:
When I make changes to the source files included in the bundle, the Uno-generated CSS reloads and is applied as expected. I believe this is because the bundler source triggers the rebuild, and imports But changing external sources does not trigger a rebuild. It triggers invalidation, rebuilds UnoCSS, and writes a file to To reproduce this issue in my repository, launch the What I did appears to be in line with the documentation of the Virtual Modules plugin, so I'm not sure what I did wrong. Any tips? Note: the reason I am using a "trigger" file instead of adding dependencies on the external files directly, is because these dependencies are defined using Regex and globs, and it would be difficult to reduce them to context directories and individual file references on demand. It would be much easier to rely on Note 2: I have also tried using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I'm excited to hear that you're building a UnoCSS plugin for Rsbuild! I've received feedback from users about some unresolved issues with Regarding the I think rsbuild-plugin-virtual-module should set the Before we release a new version of rsbuild-plugin-virtual-module, you can temporarily update the configuration in your rsbuild.config.ts to test this: import { defineConfig } from "@rsbuild/core";
import { pluginUnoCss } from "../src/index.js";
export default defineConfig({
plugins: [pluginUnoCss()],
server: {
port: 3001,
strictPort: true,
},
+ tools: {
+ rspack: {
+ watchOptions: {
+ // or set "ignored: /\.git/" to watch the entire node_modules
+ ignored: /[\\/](?:\.git|node_modules(?![\\/]\.rsbuild-virtual-module))[\\/]/,
+ },
+ },
+ },
}); |
Beta Was this translation helpful? Give feedback.
I'm excited to hear that you're building a UnoCSS plugin for Rsbuild! I've received feedback from users about some unresolved issues with
@unocss/webpack
. I believe a dedicated plugin for Rsbuild would provide a much better experience.Regarding the
addDependency
issue you encountered, I did a quick investigation and found thataddDependency
is working correctly. The key issue is that Rspack doesn't watch files in node_modules by default. This can be changed by configuring the watchOptions.ignored option.I think rsbuild-plugin-virtual-module should set the
watchOptions.ignored
option by default to enable watching of virtual modules innode_modules/.rsbuild-virtual-module
. I'll talk to @S…