vite-plugin-shadow-style icon indicating copy to clipboard operation
vite-plugin-shadow-style copied to clipboard

Feature request: Custom injection target

Open m44rten1 opened this issue 2 years ago • 3 comments

Hello,

First off, I'd like to express my appreciation for your work on the ShadowStyle plugin. However, I've encountered a scenario where being able to specify a custom injection target would greatly enhance its utility in my project.

My project involves lazy loading styles, and as a result, I don't inject them at the entry point. This leads to a need for more flexibility in terms of where the styles are injected. To address this, I propose adding an option to the ShadowStyle plugin that allows users to define a custom injection target.

Here's a rough idea of how this feature could be implemented:

...
plugins: [
  shadowStyle({ injectionTarget: 'my-injection-target' }),
],
...

m44rten1 avatar Nov 16 '23 21:11 m44rten1

Hey, thank you for using the plug-in and providing this idea! What would the injection target refer to, in your example? A DOM node, or a placeholder string to swap with the actual output CSS?

hood avatar Nov 20 '23 07:11 hood

Hey! I see that my comment wasn't clear. my-injection-target would refer to a file-name. I believe that the plugin only allows 'entry' files, if I understand the isInjectionTarget method.

m44rten1 avatar Feb 02 '24 13:02 m44rten1

Yes, isInjectionTarget currently scans for output files and returns true if the file has the isEntry flag set by Vite. We can definitely customise this behaviour and allow for custom definition of an entrypoint.

hood avatar Apr 24 '24 11:04 hood