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

[Feature]: Split chunk & return the path #4462

Open
felixmosh opened this issue Jan 30, 2025 · 9 comments
Open

[Feature]: Split chunk & return the path #4462

felixmosh opened this issue Jan 30, 2025 · 9 comments

Comments

@felixmosh
Copy link

What problem does this feature solve?

I've an intersting use-case, when bundling Node server.

There are some time Workers that expect to get a file path.
I would like it to work exactly like rsbuild works which native worker_threads.

import { Worker } from 'bullmq'
import { pathToFileURL } from 'url';

const processorUrl = pathToFileURL(__dirname + '/my_procesor.ts');

worker = new Worker(queueName, processorUrl);

It would be cool it rsbuild / rspack would create a chunk from the my_processor.ts file, and pass the path to it. Just like it does with native worker_threads.

I've tested it, looks like it does creates a asset chunk from it, but it doesn't process the typescript.

What does the proposed API look like?

import { Worker } from 'bullmq'

worker = new Worker(queueName, new URL('/my_procesor.ts', import.meta.url));

@chenjiahan
Copy link
Member

Thanks for the feature request. While we understand your use case with bullmq workers, we believe this is outside the scope of Rspack's core responsibilities. We want to keep Rspack focused on its primary bundling responsibilities rather than adding features for specific libraries.

The processing of worker files is specific to BullMQ's implementation, and we recommend handling this at the application level instead.

@felixmosh
Copy link
Author

Thank you for a quick response.
It looks like there something that handles new URL as an asset, maybe, there is some config that can be changed?

@chenjiahan
Copy link
Member

chenjiahan commented Feb 1, 2025

Set module.parser.javascript.url to false should disable the new URL parsing:

// rsbuild.config.ts
export default defineConfig({
  tools: {
    rspack: {
      module: {
        parser: {
          javascript: {
            url: false,
          },
        },
      },
    },
  },
});

https://rspack.dev/config/module#moduleparserjavascripturl

@felixmosh
Copy link
Author

felixmosh commented Feb 1, 2025

This just disables the parsing, no?
It would not create a chunk out of it, correct?

@chenjiahan
Copy link
Member

Correct, no chunk will be created.

@felixmosh
Copy link
Author

Is it possible to keep the URL parsing and just changing the type? instead of asset type to js/auto?

@felixmosh
Copy link
Author

Maybe It can be used with this??
https://rspack.dev/config/module#moduleparserjavascriptworker

@chenjiahan
Copy link
Member

module.parser.javascript.worker is definitely worth a try

@felixmosh
Copy link
Author

I've tried:

        config.module.parser.javascript.worker = ['Worker from bullmq', '...'];

without success, what is the correct syntax?

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

2 participants