Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add direct CSS loading and static file loading to module server #116

Merged
merged 8 commits into from
Jun 28, 2021

Conversation

calebeby
Copy link
Member

@calebeby calebeby commented Jun 25, 2021

Before this PR, CSS was supported in this way:

You could use loadCSS:

await utils.loadCSS('./something.sass') // or css, etc

You could use css imports from JS files:

import './asdf.css'

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):

import './asdf.sass'

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):

import './asdf.css' // => transpiles to import './asdf.css?import'

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 used

Also, the HTTP server now supports static assets (like fonts/images loaded via CSS - which I ran into on cloudfour.com)

@calebeby calebeby marked this pull request as ready for review June 25, 2021 18:39
Copy link
Member

@gerardo-rodriguez gerardo-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🎉

@calebeby calebeby merged commit 5afa0a6 into main Jun 28, 2021
@calebeby calebeby deleted the css-and-static branch June 28, 2021 23:15
@github-actions github-actions bot mentioned this pull request Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants