Allow plugins to overwrite built-in loaders#522
Conversation
🦋 Changeset detectedLatest commit: 31c83e7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
With this change default loaders are only added if no other prefix is present already in the path id
f913503 to
31c83e7
Compare
|
Size Change: -47 B (0%) Total Size: 733 kB
ℹ️ View Unchanged
|
|
I am getting uncaught errors |
|
Okay, the above exception is thrown whenever I hard-refresh the page with |
|
I tested this PR. The main goal is indeed achieved, and as demonstrated by your integration tests, this closes #449 However, this PR breaks "nested absolute path import" as described here: ...I will be searching for a workaround for this, as it is an important feature in a codebase where relative paths such as |
|
Ah, interesting: the "nested absolute path import" only occurs with JSON files, not SVG. I will post a new issue once I've narrowed this down. |
|
Okay, I found a workaround for JSON files, using the same trick I used before for SVG files :) In the if (config.mode === 'start') id = `${id}${'\0'}`;..and in if (config.mode === 'start') id = id.replace(/\0$/, '');I am filing a new issue. |
|
@danielweck thanks for giving the fix a go 👍 The path aliasing thing is next on my list and I think I have an idea of where things get weird. |
|
I filed this issue: #524 |
With this change default loaders are only added if no other prefix is present already in the path id.
I've tried a few other alternatives to the changes here, but they all end up working around limitations in rollup's plugin system and make user plugins pretty verbose to write. The gist of the problem is that with custom plugins we'll have to deal with recursive resolution early on.
The way that this usually occurs is that a custom plugin strips their prefix and passes the stripped id on to
this.resolve. The plugins resolved by that have no knowledge about the original path and just see./foo.jsonand add their prefix, because they assume that this is the full import specifier. This leads to errors like the one outlined in #449 wheremy-json:./foo.jsonwill be turned intomy-json:json:./foo.json. The changes in this PR ensure thatmy-json:./foo.jsonstays that way.We essentially split up resolution and applying default loaders into two distinctive concerns. The plugins itself should only match when their prefix is present. The
defaultLoaderplugin ensures that "raw" specifiers like./foo.jsonare turned intojson:./foo.jsonfrom where we can just reused the existing resolution semantics.Fixes #449