swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

swc-loader does not expose `filename` or other programmatic options to plugins #36

Open rametta opened 2 years ago

rametta commented 2 years ago

When using swc, there is an option for providing the filename which can be passed down to plugins, but when using the swc-loader, the filename is not passed automatically as in the way babel-loader does it.

This makes it impossible for swc plugins using swc-loader to know the current filename and path being processed and have logic around that, along with all the other swc programatic options that could be useful to plugins.

PepijnSenders commented 2 years ago

@rametta I created a patch for our SWC loader:

programmaticOptions.plugin = programmaticOptions.plugin({
  filename,
  sourceFileName: programmaticOptions.sourceFileName
});

The loader has the filename, and just passing the plugin to the loader like this: (options) => (m) => new SWCPlugin(options).visitProgram(m). Not the cleanest, so not sure if I'll create a PR for this yet, but works for us.