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

import assertions (especially for CSS) #211

Closed
dmail opened this issue Oct 7, 2021 · 2 comments · Fixed by #212
Closed

import assertions (especially for CSS) #211

dmail opened this issue Oct 7, 2021 · 2 comments · Fixed by #212
Assignees
Labels
needs investigation Needs investigation before going further new feature New feature or request nice to have Would be better but not critical

Comments

@dmail
Copy link
Member

dmail commented Oct 7, 2021

Needs to investigate how to support that (it's supported in latest chrome and edge)

https://web.dev/css-module-scripts/

Needs to find how to:

  • Would rollup be able to parse them and provide that information to rollup hooks?
  • Feature detect for dev server
  • What would it transpile to?
  • How to polyfill constructable stylesheet?
@dmail dmail added needs investigation Needs investigation before going further new feature New feature or request nice to have Would be better but not critical labels Oct 7, 2021
@dmail
Copy link
Member Author

dmail commented Oct 8, 2021

Things to try:

  1. Enable acorn plugin for import assertion in rollup
  2. Enable babel plugin to support import assertion syntax
  3. Write a custom babel plugin transforming
p {
  color: red;
}

Into

const stylesheet = new CSSStyleSheet();

stylesheet.replaceSync(`p {
  color: red;
}`);

export default stylesheet;
  1. Find how to enable this babel plugin ONLY when file is imported by
import sheet from './styles.css' assert { type: 'css' };

This point is problematic because it means the representation of a ressource depends how it's requested.
It means this reponsability do not belong to the server but rather the code importing the file I guess 🤔

@dmail
Copy link
Member Author

dmail commented Oct 8, 2021

So it's inside systemjs and inside rollup load transform hook that we should wrap the CSS inside an export default

@dmail dmail mentioned this issue Oct 10, 2021
13 tasks
@dmail dmail self-assigned this Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation Needs investigation before going further new feature New feature or request nice to have Would be better but not critical
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant