[Bug]: When in bundleless mode, rspack plugins do not call `normalModuleFactory.hooks.resolve` on import declarations
Version
System:
OS: macOS 15.1.1
CPU: (10) arm64 Apple M1 Max
Memory: 96.69 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Browsers:
Chrome: 141.0.7390.108
Firefox: 138.0.3
Safari: 18.1.1
npmPackages:
@rslib/core: ^0.16.0 => 0.16.0
Details
When rslib is set to output in bundleless mode (bundle: false), any registered rspack plugins do not call the normalModuleFactory.hooks.resolve hook on import declarations in the source files.
When rslib is set to output in bundleless mode (bundle: false), a rspack plugin provided to the rslib configuration (tools.rspack.plugins) will not call the normalModuleFactory.hooks.resolve hook for imports in the source files. It will call it on the result of the source.entry glob, but it does not loop through the imports of each source file, calling the hook, as I would expect.
I would expect this especially because it does call the beforeResolve hook on these imports, but then does not call resolve.
This is needed for my use case, as I am using a plugin that, combined with a component library, generates CSS files at build time. It will add the imports to the source files as needed, and then it waits for the the resolve to be called on the path, in order to write out the corresponding CSS file. Because resolve is not being called, the plugin is failing to write out the CSS files.
Reproduce link
https://github.com/davidferguson/rslib-bundle-noresolve
Reproduce Steps
Described in the reproduction repo readme
Currently, the implementation of bundleless mode treats all files as entries and externalizes all requests, so the resolve hook will not be executed.
We are implementing a new solution for ESM format based on preserve modules, so stay tuned.
Thank you for the quick reply @Timeless0911!
We are implementing a new solution for ESM format based on preserve modules, so stay tuned.
Will this only apply when format: 'esm'? What about format: 'cjs'?
Will this only apply when format: 'esm'? What about format: 'cjs'?
Our current focus is on enhancing esm, and there are no plans yet to optimize cjs output in the short term until advanced esm is stable.