Anidetrix / rollup-plugin-styles

🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
https://anidetrix.github.io/rollup-plugin-styles
MIT License
242 stars 43 forks source link

Relative Asset URL in mode 'inject' #162

Open CxRes opened 3 years ago

CxRes commented 3 years ago

This might be a question due to my lack of understanding or maybe a request for enhancement!

I have a plugin to my main program with injected css, say myPlugin which I dynamically load using the import('./plugins/myPlugins/plugin.js') statement. The plugin contains assets that I am extracting to myPlugin/assets folder and are correctly mapped relative to myPlugin. Now when I load this plugin from main program, it expects the assets in ./assets and not ./plugins/myPlugins/assets. From what I understand this is because css resolve code in the bundle resolves paths relative to src in <script type='module' src='./main.js'> and not relative to the ./plugins/myPlugin./plugin.js.

Is this behaviour by design? Is there a way to modify this behaviour to make css loading relative? (Extracting css does not seem to be sensible here because I have to then have a mechanism to load the css separately, which seems a super weird way of loading a plugin, especially due to the extra burden of tracking multiple entry points per format). Any other suggestions of resolving this conundrum other that literally copying the contents of ./plugins/myPlugin/assets to ./assets?

I'd really appreciate any input (it is literally the last thing I am stuck on for my work)!