Re: [csswg-drafts] [CSS Import Once] @import-once, or some syntax for importing a stylesheet only once (#6130)

In the comment here:

- https://github.com/w3c/csswg-drafts/issues/9350#issuecomment-1965795123

I've shown an idea for importing things in a more *module* like way. For example, import a mixin from somewhere:

```css
@import --foo from './my-mixins.css'

/* --foo is usable only within this file, not in any other file, not global. */ 
.some-class {
  @apply --foo;
}
```

The idea there is it behaves more like ES Modules: we import what we need into our files, the engine determines the dependency graph for us, and modules do not re-evaluate more than once.

Some things like functions and mixins may perhaps always be module-scoped (even if the module that executed created global styles) and imported into other files explicitly (just like a JavaScript file that both creates globals and exports things).

We could potentially then also add features like module variables which are scoped to modules, and usable only where imported (current CSS vars/properties would still exist as a "global" feature).

-- 
GitHub Notification of comment by trusktr
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6130#issuecomment-1965835426 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 27 February 2024 05:50:53 UTC