-
-
Notifications
You must be signed in to change notification settings - Fork 640
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
feat: support loader-runner and pitching #2808
Conversation
🦋 Changeset detectedLatest commit: 303b79b The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
45357ef
to
ec5b85a
Compare
it would be better if we have a example about pitching loader |
!bench |
@hardfist Pitching loader is often used with inline loaders to initiate a new loader pipeline like how style-loader did, rspack does not support inline loaders now, I would like to add an example after style-loader or something else is supported. |
Benchmark Results
|
1cfda71
to
97da9f5
Compare
9990264
to
4bbbcd5
Compare
* refactor: init * refactor: replace with new loader * chore: rename * fix: execution order * chore: lint * chore: wip testing * feat: make it compile * feat: apply loader to rust * feat: js wip * feat: impl original content for pitching * fix: fix typo * feat: it works! * feat: update message when last loader returns nothing * fix: fix control flow * chore: add more comments * fix: fix resolving * chore: remove testing * feat: add some optimizations * chore: lint * chore: cleanup * fix: hmr * test: add pitching test * chore: cleanup * chore: lint * add cgst * chore: lint
Related issue (if exists)
closes #2394
closes #1750
closes #1751
Summary
This PR refactors the loader architecture and adapts webpack's loader-runner to rspack.
Pitching loader is supported for both Rust and JS side from now on.
The old architecture is a quite simple version, which only supports loaders for normal stage.
Pitching loader does not put into consideration. The basic concept of the old version is to
convert the normal loader to a native function which can be called from the Rust side.
Furthermore, for performance reason, Rspack also composes loaders from the JS side to
mitigate the performance issue of Node/Rust communications.
In this new architecture, loaders will not be converted directly into native functions.
Instead, it is almost the same with how webpack's loader-runner resolves its loaders, by
leveraging the identifier. Every time Rspack wants to invoke a JS loader, the identifiers will
be passed to the handler passed by Node side to process. The implementation also keeps
the feature of composing JS loaders for performance reason.
See #2846 for more details on the architecture.
Tracking PRs:
loader-runner
for preparing to supportvue-loader
andpitching loader
#2789🤖 Generated by Copilot at 2c6ea7c
This pull request refactors the
rspack_core
andrspack_loader_runner
crates to use a newResolverFactory
abstraction for resolving module dependencies and a newrun_loaders
function for running loaders. It also adds support for more complex resource URLs, loaders, and modules, and implements hot module replacement (HMR) for modules. It removes unused and outdated code and simplifies the code with thederivative
crate.Walkthrough
🤖 Generated by Copilot at 2c6ea7c
LoaderRunnerRunner
type and replace it with theResolverFactory
type and therun_loaders
function to simplify the loader running and resolving logic (link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link)CompilerContext
type and theBuildContext
type to hold the common compiler options and theResolverFactory
instance that are used by different modules and loaders (link, link)LoaderRunnerPluginProcessResource
type and use it in theNormalModule
struct to support plugin hooks for the loader runner (link, link)resource_fragment
,resource_query
, andresource_path
fields to theResourceData
struct to support more complex resource URLs and parameters (link)identifier
method of theNormalModuleFactory
struct to use theidentifier
method of theLoader
trait instead of thename
method to support more complex and dynamic loaders and modules (link)derivative
crate and theDerivative
derive macro to customize theDebug
implementation for some structs and enums in therspack_core
crate (link, link, link, link, link, link, link)rspack_loader_runner2
crate torspack_loader_runner
and update therspack_core
crate to use the new version (link, link)rspack_loader_runner
crate and its files (link, link, link, link, link, link, link, link)