marco-prontera / vite-plugin-css-injected-by-js

A Vite plugin that takes the CSS and adds it to the page through the JS. For those who want a single JS file.
MIT License
429 stars 26 forks source link

Improving debugging for relativeCSSInjection #116

Closed grumd closed 1 year ago

grumd commented 1 year ago

When using relativeCSSInjection, cssCodeSplit needs to be enabled. This is not documented and unfortunately I didn't know that until I opened the source code of this plugin.

I was using build.lib option, so in my configuration build.cssCodeSplit was undefined, and Vite by default sets it to false after resolving configs.

image

This plugin only checks if (config.build.cssCodeSplit == false) before sending out a warning.

My suggestions:

  1. Can configResolved(_config) be used for this check? It doesn't have env.command but it will have the resolved false value for cssCodeSplit after Vite decides on the defaults.
  2. We could also change the condition to if (config.build.cssCodeSplit == false || (!config.build.cssCodeSplit && config.build.lib)) but I don't really like that. Vite could change their defaults at any time.
  3. Add the information about cssCodeSplit to the readme. I'll send a PR for that shortly.
marco-prontera commented 1 year ago

Hi, thank you for the issue. I think it's a good starting point the PR you proposed. I will merge it asap, thank you for the contribution. I will valuate others solutions you proposed, but for know I think it's enough