Skip to content

[Bug]: Plugin api.transform runs when file changes that does not match test #5176

@Profesor08

Description

@Profesor08

Version

System:
    OS: Windows 11 10.0.26100
    CPU: (24) x64 AMD Ryzen 9 3900XT 12-Core Processor           
    Memory: 8.81 GB / 31.92 GB
  Browsers:
    Edge: Chromium (131.0.2903.86)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    @rsbuild/core: ^1.3.16 => 1.3.16

Details

When the api.transform is used, it runs on unrelated file change. This brings unexpected behavior and unexpected transforms.

In next example, api.transform runs always when .ts, .css, .html file is changed. And triggers transform for both .html files.

Example:

import { type RsbuildPlugin, defineConfig, logger } from "@rsbuild/core";

export default defineConfig(() => {
  return {
    plugins: [
      {
        name: "test-plugin",
        setup(api) {
          api.transform({ test: /\.html$/ }, ({ resource }) => {
            logger.error(resource, { timestamp: Date.now() });

            return `export default "${resource}";`;
          });
        },
      } satisfies RsbuildPlugin,
    ],

    source: {
      entry: {
        index: {
          import: "./src/ts/index.tsx",
        },
        main: {
          import: "./src/ts/main.tsx",
        },
      },
    },

    html: {
      template: ({ entryName }) => `./src/${entryName}.html`,
    },
  };
});

rsbuild-api-transform-bug.zip

Reproduce link

Repo in attachments

Reproduce Steps

  1. npm install
  2. npm run dev
  3. make change in .css file
  4. check console log

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions