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]: hmrC.css is missing after the css_loading runtimeModule is changed #5571

Closed
tmkx opened this issue Feb 1, 2024 · 0 comments · Fixed by #5661
Closed

[Bug]: hmrC.css is missing after the css_loading runtimeModule is changed #5571

tmkx opened this issue Feb 1, 2024 · 0 comments · Fixed by #5661
Assignees
Labels
bug Something isn't working

Comments

@tmkx
Copy link
Contributor

tmkx commented Feb 1, 2024

System Info

@rspack/core: 0.5.3

Details

__webpack_require__.hmrC.css is missing after I changed the css_loading runtime module.

Reproduce link

No response

Reproduce Steps

// rsbuild.config.ts
import { Rspack, defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
  plugins: [pluginReact()],
  dev: {
    writeToDisk: true, // inspect output
  },
  tools: {
    bundlerChain(chain) {
      chain.plugin('TestPlugin').use(TestPlugin);
    },
  },
});

class TestPlugin {
  apply(compiler: Rspack.Compiler) {
    compiler.hooks.thisCompilation.tap('TestPlugin', (compilation) => {
      compilation.hooks.runtimeModule.tap('TestPlugin', (module) => {
        if (module.name !== 'css_loading' || !module.source) return;
        const originCode = module.source.source.toString('utf-8');

        module.source.source = Buffer.from(
          originCode
            .replace(/document\.(getElementsByTagName|querySelectorAll)/g, `(globalThis.APP_ROOT||document).$1`)
            .replace(/document\.head/g, `(globalThis.APP_STYLE_ROOT||document.head)`),
          'utf-8',
        );
      });
    });
  }
}
@tmkx tmkx added bug Something isn't working pending triage The issue/PR is currently untouched. labels Feb 1, 2024
@jerrykingxyz jerrykingxyz removed the pending triage The issue/PR is currently untouched. label Feb 2, 2024
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

Successfully merging a pull request may close this issue.

3 participants