Skip to content

Commit

Permalink
[SyntheticModules] Implements CSS Modules
Browse files Browse the repository at this point in the history
This is the final change required for CSS Modules to be utilized by developers.
Following the acceptance of this change, if you run chromium with the CSSModules runtime flag, the following is now valid syntax:

<script type="module">
    import sheet from "./example.css";
</script>

CSS Modules Explainer:
https://github.com/w3c/webcomponents/blob/gh-pages/proposals/css-modules-v1-explainer.md

CSS Modules Spec PR:
whatwg/html#4898

Bug: 967018
Change-Id: Ifdee5b92259fb7e4e9c8f9aa88e69a98eb55c551
  • Loading branch information
Sam Sebree authored and chromium-wpt-export-bot committed Nov 11, 2019
1 parent 0869400 commit 8a05d58
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>

<head>
<title>import-css-module-worker</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<h1>import-css-module-worker</h1>
<script>
async_test(function (test) {
const worker = new Worker("./modules/worker.js", { type: "module" });
worker.onmessage = test.step_func(() => { assert_unreached("A CSS Module within a web worker should not load.")});
worker.onerror = test.step_func_done();
}, "A CSS Module within a web worker should not load.");
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>

<head>
<title>import-css-module-basic</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<h1>import-css-module-basic</h1>
<script type="module">
import v from "./modules/basic.css"
document.adoptedStyleSheets = [v];
test(function () {
assert_equals(getComputedStyle(document.querySelector('#test')).backgroundColor, "rgb(255, 0, 0)", "CSS module should import correctly on top level document");
}, "Test basic CSS module import");
</script>

<div id="test">
I am a test div.
</div>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#test {
background-color:red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./basic.css"

0 comments on commit 8a05d58

Please sign in to comment.