Add direct CSS loading and static file loading to module server #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this PR, CSS was supported in this way:
You could use loadCSS:
You could use css imports from JS files:
The CSS file would be piped through PostCSS and converted into a JS script that injects the CSS as a <style> tag.
Also, sass/less/stylus/less were supported (via rollup-plugin-postcss):
However, if you requested a sass/css file via HTTP, you would get back a JS file with the code to inject the CSS. This is not good.
Now, in addition to those use cases, CSS is supported at the HTTP server layer, so if you request a CSS file via something other than a JS import, it will end up being a CSS file rather than a JS file.
This is done by adding
?import
to imports in JS files to distinguish between JS/CSS (same as Vite does, and similar to what WMR does):Then the HTTP server knows to return a JS file with the CSS injector if
?import
exists, and CSS directly otherwise.An example use-case for this is if
@import
is usedAlso, the HTTP server now supports static assets (like fonts/images loaded via CSS - which I ran into on cloudfour.com)