Re: [w3c/webcomponents] CSS Modules (#759)

This feature doesn't interfere with the userland solution in any way. The userland solutions are implemented as custom transforms that will absolutely still work with no changes whatsoever, because the CSS module import doesn't reach the browser.

Those transforms can carry on from now till eternity, or they can be updated to perform a new subset of their transforms on the CSS contents and use CSS modules for loading and parsing. Systems that provide more exports from CSS than this proposal (like classes) can still do so by generating the necessary JS.

The example taken from https://github.com/css-modules/css-modules:

style.css:
```css
.className {
  color: green;
}
```

app.js:
```js
import styles from "./style.css";
// import { className } from "./style.css";

element.innerHTML = '<div class="' + styles.className + '">';
```

can be transformed to:

style.css:
```css
.a /* renamed from .className */ {
  color: green;
}
```

style.css.js:
```js
import {style} from './style.js';
document. adoptedStyleSheets = [...document. adoptedStyleSheets, style];
const classes = {
  className: 'a',
};
export default classes;
export const className = classes.a;
```

app.js:
```js
import styles from "./style.css.js";
// import { className } from "./style.css.js";

element.innerHTML = '<div class="' + styles.className + '">';
```

So this preserves existing semantics and leverages native loading. If they wanted to update the transform, say to be usable with shadow DOM, they could have a version that exports the stylesheet and doesn't automatically apply it to the document.

There are a ton of options on how the basic semantics of importing a stylesheet can be used and extended for all kinds of cases and bridged to existing userland systems. It'd be more useful if general claims that this proposal is in conflict with such systems, and especially that it might "do harm", were accompanied with more specific examples.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/759#issuecomment-520660048

Received on Tuesday, 13 August 2019 02:06:19 UTC