evanw / evanw/esbuild

After executing build.Onload execution is passed to the loader

Open
#2,872 1 comment 0 reactions 0 assignees View on GitHub
plugins
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I have written the following plugins:

```js
const pathReplacePlugin = ((filter) => {

return {
name: "path-replace",
setup(build){
build.onLoad({ filter: /\.svelte$/ }, (opts) => {
let source = fs.readFileSync(opts.path, 'utf8').toString();
source = source.replace(/(\/static\/images|@\{img_path\})/g, function handleReplace(match) {

let dirname = __dirname
const relPath = path.relative(opts.path, dirname).replace(/\\/g, '/')

let relativeUrl = Array(this.file.relative.split(path.sep).length + 1).fill('..').join('/')
relativeUrl += '/images';

return relativeUrl;
});
return {
contents: source,
pluginData: opts.pluginData,
};
})
}
}
});
```

according to my idea, after it, the control should go to *esbuildSvelte* according to the order in which they are listed in the plugins *option*:

![image](https://user-images.githubusercontent.com/40761960/215138410-59bb8485-0617-42ca-ac65-42e3de59d71e.png)

but I ran into the following error:

![image](https://user-images.githubusercontent.com/40761960/215139524-dad0ea45-0a33-4143-87b3-966968581677.png)

I assume that this is due to the fact that management immediately goes to the default loader (`js`). And then the collector assumes that the tag is js (since it is imported into a js file, it may seem that this is the case), but it is not. The next plugin on the list should handle the processing, not the loader.

Is there a way to transfer control to the next plugin, bypassing loaders?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the build.onLoad callback and the plugins option shown in the issue, then reproduce the behavior with the path-replace and esbuildSvelte plugins in that order. Compare the observed loader selection with esbuild's plugin lifecycle documentation; done means establishing whether control can bypass the loader and documenting or correcting the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.