Skip to content

Commit 151ea88

Browse files
authored
Add purgecss-postcss plugin to remove unused CSS from the bundle (#281)
* Add Vocabulary Select implementation instead of buefy select * Revert "Add Vocabulary Select implementation instead of buefy select" This reverts commit 6f09c17 * Add postcss to purge unused css * Make text inside modals correct color * Document whitelisting classes in PurgeCSS PostCSS plugin
1 parent b5de735 commit 151ea88

File tree

6 files changed

+145
-49
lines changed

6 files changed

+145
-49
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ For information on contributing, please see [Creative Commons' Contribution Guid
2828

2929
If you create a PR for your work, but you are not finished yet, please include `WIP:` in the beginning of your PR title. When your work on your PR is completed and you are ready for a final review, please remove the `WIP:` prefix from the title to indicate that your work is done.
3030

31-
Here's a [handy link](https://github.com/creativecommons/chooser/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22+-label%3A%22in+progress%22) that will show you all open issues in this repo that have the `help wanted` tag, but do not have the `in progress` tag.
32-
All issues in this list are up for grabs!
31+
Here's a [handy link](https://github.com/creativecommons/chooser/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22+-label%3A%22in+progress%22) that will show you all open issues in this repo that have the `help wanted` tag, but do not have the `in progress` tag.
32+
All issues in this list are up for grabs!
3333
If it says "No results matched your search", then there are no issues currently up for grabs.
3434

3535
*If no progress has been made on an issue for seven days after assignment, the assignment will be removed to allow others to contribute.*
@@ -42,8 +42,10 @@ $ npm run test
4242
```
4343
To run e2e tests, you must have Java installed. [[download Java here](https://java.com/download/)]
4444

45+
## CSS Build
46+
The Chooser uses PostCSS plugin for PurgeCSS to make CSS bundle size smaller. It automatically removes unused CSS based on the classes found in the final built bundle. Some styles for dynamic components or dynamically-imported files can also be removed. If you find that the built site misses some styles, you can manually add the necessary classes or Regex expressions to the `safelist` array in the `postcss.config.js` file.
4547

4648
## Deployment
47-
The chooser is deployed to GitHub Pages. The source files for the beta deployment are contained in the `./docs/` dir, and are live. Any changes to this dir's contents will be automatically deployed, so please take care when making modifications to this location.
49+
The chooser is deployed to GitHub Pages. The source files for the beta deployment are contained in the `./docs/` dir, and are live. Any changes to this dir's contents will be automatically deployed, so please take care when making modifications to this location.
4850

49-
To update the dist bundle, run ```$ npm run build```, and copy the generated files from `./dist/` to `./docs/`, taking care to not delete the CNAME file in `./docs/`.
51+
To update the dist bundle, run ```$ npm run build```. This and copy the generated files from `./dist/` to `./docs/`, taking care to not delete the CNAME file in `./docs/`.

package-lock.json

Lines changed: 54 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"@creativecommons/vocabulary": "^2020.11.3",
2323
"@creativecommons/vue-vocabulary": "^2020.11.3",
24+
"@fullhuman/postcss-purgecss": "^3.1.3",
2425
"@linusborg/vue-simple-portal": "^0.1.4",
2526
"@sentry/vue": "^5.29.2",
2627
"buefy": "^0.9.4",

postcss.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const IN_PRODUCTION = process.env.NODE_ENV === 'production'
2+
3+
module.exports = {
4+
plugins: [
5+
IN_PRODUCTION &&
6+
require('@fullhuman/postcss-purgecss')({
7+
content: ['./public/**/*.html', './src/**/*.vue'],
8+
defaultExtractor(content) {
9+
const contentWithoutStyleBlocks = content.replace(
10+
/<style[^]+?<\/style>/gi,
11+
''
12+
)
13+
return (
14+
contentWithoutStyleBlocks.match(
15+
/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g
16+
) || []
17+
)
18+
},
19+
safelist: [
20+
/-(leave|enter|appear)(|-(to|from|active))$/,
21+
/^(?!(|.*?:)cursor-move).+-move$/,
22+
/^router-link(|-exact)-active$/,
23+
/data-v-.*/,
24+
/is-text/,
25+
/control/,
26+
/select/,
27+
/^tabs.*/,
28+
/is-boxed/,
29+
/app-modal/,
30+
/overlay/,
31+
/^modal.*/,
32+
/padding.*/,
33+
/icon/,
34+
/close-button/,
35+
/has-color-gray/,
36+
/is-size-.*/
37+
]
38+
})
39+
]
40+
}

src/components/HeaderSection.vue

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
<template>
2-
<b-navbar wrapper-class="container">
3-
<template slot="brand">
4-
<b-navbar-item>
5-
<a
6-
class="logo"
7-
href="/"
8-
>
9-
<img
10-
src="../assets/chooser.svg"
11-
alt="Creative Commons License chooser"
2+
<header>
3+
<nav class="navbar">
4+
<div class="container">
5+
<div class="navbar-brand">
6+
<a
7+
class="logo"
8+
aria-current="page"
9+
href="/"
1210
>
13-
</a>
14-
</b-navbar-item>
15-
</template>
16-
<template slot="end">
17-
<b-navbar-item
18-
href="https://docs.google.com/forms/d/e/1FAIpQLSfF7MCKxlPsPuMn17v_sLYWMkxBkudQSPXCXoJKjh5GCtx63g/viewform"
19-
title="Feedback"
20-
class="navbar-item-feedback"
21-
>
22-
{{ $t('header.nav-feedback') }}
23-
<i class="icon external-link" />
24-
</b-navbar-item>
25-
</template>
26-
</b-navbar>
11+
<img
12+
src="../assets/chooser.svg"
13+
alt="Creative Commons License chooser"
14+
height="40"
15+
width="169"
16+
>
17+
</a>
18+
<a
19+
role="button"
20+
aria-label="menu"
21+
aria-expanded="false"
22+
class="navbar-burger"
23+
>
24+
<span aria-hidden="true" />
25+
<span aria-hidden="true" />
26+
<span aria-hidden="true" />
27+
</a>
28+
</div>
29+
<div class="navbar-menu navbar-end">
30+
<a
31+
class="navbar-item navbar-item-feedback"
32+
href="https://docs.google.com/forms/d/e/1FAIpQLSfF7MCKxlPsPuMn17v_sLYWMkxBkudQSPXCXoJKjh5GCtx63g/viewform"
33+
title="Feedback"
34+
>
35+
{{ $t('header.nav-feedback') }}
36+
<i class="icon external-link" />
37+
</a>
38+
</div>
39+
</div>
40+
</nav>
41+
</header>
2742
</template>
2843

2944
<script>
@@ -39,15 +54,13 @@ export default {
3954
.navbar-burger {
4055
background-color:white;
4156
}
42-
.navbar-item-feedback {
43-
padding-right: 30%;
44-
font-family: Roboto Condensed,sans-serif;
45-
font-size: 16px;
57+
.navbar-item.navbar-item-feedback {
58+
font-size: 1rem;
4659
font-weight: bold;
47-
color: #787878!important;
60+
color: #787878;
4861
transition: color 300ms ease;
4962
&:hover {
50-
color: #fb7729!important;
63+
color: #fb7729;
5164
background-color: white;
5265
}
5366
}

src/components/HelpSection.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ export default {
283283
padding-top: var(--h-padding);
284284
padding-bottom: var(--h-padding);
285285
margin: 0;
286+
color: #333333;
286287
287288
article {
288289
max-width: 85ch;

0 commit comments

Comments
 (0)