Skip to content

Commit 458c670

Browse files
authored
ships CSS-in-JS as part of each Web Component's dep graph (GoogleChrome#2245)
* Ships CSS-in-JS as part of each Web Component's dep graph. * fix unresolved behavior on header
1 parent e3fafbb commit 458c670

File tree

30 files changed

+80
-57
lines changed

30 files changed

+80
-57
lines changed

build.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const path = require("path");
2222
const log = require("fancy-log");
2323
const rollupPluginNodeResolve = require("rollup-plugin-node-resolve");
2424
const rollupPluginCJS = require("rollup-plugin-commonjs");
25+
const rollupPluginPostCSS = require("rollup-plugin-postcss");
2526
const rollupPluginVirtual = require("rollup-plugin-virtual");
2627
const rollupPluginReplace = require("rollup-plugin-replace");
2728
const rollup = require("rollup");
@@ -96,6 +97,16 @@ async function buildCacheManifest() {
9697
async function build() {
9798
const generated = [];
9899

100+
const postcssConfig = {};
101+
if (isProd) {
102+
// nb. Only require() autoprefixer when used.
103+
const autoprefixer = require("autoprefixer");
104+
postcssConfig.plugins = [autoprefixer];
105+
106+
// uses cssnano vs. our regular CSS usees sass' builtin compression
107+
postcssConfig.minimize = true;
108+
}
109+
99110
// Rollup bootstrap to generate graph of source needs. This eventually uses
100111
// dynamic import to bring in code required for each page (see router.js).
101112
// Does not hash "bootstrap.js" entrypoint, but hashes all generated chunks,
@@ -106,6 +117,7 @@ async function build() {
106117
rollupPluginVirtual({
107118
webdev_config: `export default ${JSON.stringify(bootstrapConfig)};`,
108119
}),
120+
rollupPluginPostCSS(postcssConfig),
109121
...defaultPlugins,
110122
],
111123
});

compile-css.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
*/
1616

1717
require("dotenv").config();
18+
const isProd = process.env.ELEVENTY_ENV === "prod";
1819

1920
const fs = require("fs");
2021
const path = require("path");
2122
const mkdirp = require("mkdirp");
2223
const log = require("fancy-log");
2324

24-
const isProd = process.env.ELEVENTY_ENV === "prod";
25-
2625
const sassEngine = (function() {
2726
try {
2827
// node-sass is faster, but regularly fails to install correctly (native bindings)

src/lib/components/Codelab/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import {html} from "lit-element";
77
import {BaseElement} from "../BaseElement";
8+
import "./_styles.scss";
89

910
/**
1011
* Render codelab instructions and Glitch
File renamed without changes.

src/lib/components/CopyCode/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import {BaseElement} from "../BaseElement";
6+
import "./_styles.scss";
67

78
/**
89
* Renders code block that can easily be copied.

src/lib/components/Header/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@
1616

1717
/**
1818
* @fileoverview A responsive header that can trigger a side-nav.
19+
*
20+
* This does not inherit from BaseStateElement as it is not a LitElement.
1921
*/
2022

2123
import {store} from "../../store";
2224
import {expandSideNav} from "../../actions";
2325

2426
class Header extends HTMLElement {
27+
constructor() {
28+
super();
29+
30+
this.onStateChanged = this.onStateChanged.bind(this);
31+
}
32+
2533
connectedCallback() {
2634
this.hamburgerBtn = this.querySelector(".web-header__hamburger-btn");
35+
this.hamburgerBtn.classList.remove("unresolved");
2736
this.hamburgerBtn.addEventListener("click", expandSideNav);
2837

29-
this.onStateChanged = this.onStateChanged.bind(this);
3038
store.subscribe(this.onStateChanged);
3139
}
3240

3341
disconnectedCallback() {
42+
this.hamburgerBtn.removeEventListener("click", expandSideNav);
43+
3444
store.unsubscribe(this.onStateChanged);
3545
}
3646

src/lib/components/LighthouseGauge/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import {html} from "lit-element";
66
import {BaseElement} from "../BaseElement";
7+
import "./_styles.scss";
78

89
/**
910
* @extends {BaseElement}

src/lib/components/LighthouseScoresAudits/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
sortOnWeights,
1212
getAuditReferenceDocLink,
1313
} from "../../lighthouse";
14+
import "./_styles.scss";
1415

1516
const NUM_AUDITS_TO_SHOW = 10;
1617

src/lib/components/LighthouseScoresMeta/_styles.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
@import '../../../styles/settings/colors';
12
@import '../../../styles/settings/dimensions';
23
@import '../../../styles/tools/breakpoints';
4+
@import '../../../styles/tools/mixins';
35

46

57
web-lighthouse-scores-meta {

src/lib/components/LighthouseScoresMeta/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import {html} from "lit-element";
66
import {BaseElement} from "../BaseElement";
77
import {LH_HOST} from "../../lighthouse-service";
8+
import "./_styles.scss";
89

910
/* eslint-disable require-jsdoc */
1011
class LighthouseScoresMeta extends BaseElement {

0 commit comments

Comments
 (0)