Skip to content

Commit 363a3d9

Browse files
committed
perf: tree shaking Bootstrap CSS (#1736)
1 parent ddb48ed commit 363a3d9

File tree

13 files changed

+69
-34
lines changed

13 files changed

+69
-34
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ package-lock.json
1717

1818
# IDE configurations
1919
.idea
20+
.vscode
21+
!.vscode/settings.json
22+
!.vscode/extensions.json
2023

2124
# Misc
25+
_sass/dist
2226
assets/js/dist

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ exclude:
214214
- tools
215215
- README.md
216216
- LICENSE
217-
- rollup.config.js
217+
- "*.config.js"
218218
- package*.json
219219

220220
jekyll-archives:

_data/origin/basic.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ webfonts: /assets/lib/fonts/main.css
44

55
# Libraries
66

7-
bootstrap:
8-
css: /assets/lib/bootstrap/bootstrap.min.css
9-
107
toc:
118
css: /assets/lib/tocbot/tocbot.min.css
129
js: /assets/lib/tocbot/tocbot.min.js

_data/origin/cors.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Sour
1919

2020
# Libraries
2121

22-
bootstrap:
23-
css: https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css
24-
2522
toc:
2623
css: https://cdn.jsdelivr.net/npm/tocbot@4.25.0/dist/tocbot.min.css
2724
js: https://cdn.jsdelivr.net/npm/tocbot@4.25.0/dist/tocbot.min.js

_includes/head.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
{% endunless %}
7070

7171
<!-- Bootstrap -->
72-
<link rel="stylesheet" href="{{ site.data.origin[type].bootstrap.css | relative_url }}">
72+
{% unless jekyll.environment == 'production' %}
73+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
74+
{% endunless %}
7375

7476
<!-- Theme style -->
7577
<link rel="stylesheet" href="{{ '/assets/css/:THEME.css' | replace: ':THEME', site.theme | relative_url }}">

_posts/2019-08-09-getting-started.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Follow the instructions in the [Jekyll Docs](https://jekyllrb.com/docs/installat
2121

2222
There are two ways to create a new repository for this theme:
2323

24-
- [**Using the Chirpy Starter**](#option-1-using-the-chirpy-starter) - Easy to upgrade, isolates irrelevant project files so you can focus on writing.
25-
- [**GitHub Fork**](#option-2-github-fork) - Convenient for custom development, but difficult to upgrade. Unless you are familiar with Jekyll and are determined to tweak or contribute to this project, this approach is not recommended.
24+
- [**Using the Chirpy Starter**](#option-1-using-the-chirpy-starter) Easy to upgrade, isolates irrelevant project files so you can focus on writing.
25+
- [**GitHub Fork**](#option-2-github-fork) Convenient for custom development, but difficult to upgrade. Unless you are familiar with Jekyll and are determined to tweak or contribute to this project, this approach is not recommended.
2626

2727
#### Option 1. Using the Chirpy Starter
2828

@@ -32,7 +32,7 @@ Sign in to GitHub and browse to [**Chirpy Starter**][starter], click the button
3232

3333
Sign in to GitHub to [fork **Chirpy**](https://github.com/cotes2020/jekyll-theme-chirpy/fork), and then rename it to `USERNAME.github.io` (`USERNAME` means your username).
3434

35-
Next, clone your site to local machine. In order to build JavaScript files later, we need to install [Node.js][nodejs], and then run the tool:
35+
Next, clone the repository to your local machine, make sure it has [Node.js][nodejs] installed, then go to the root directory of the repo and run the following command:
3636

3737
```console
3838
$ bash tools/init
@@ -45,7 +45,7 @@ The above command will:
4545

4646
1. Check out the code to the [latest tag][latest-tag] (to ensure the stability of your site: as the code for the default branch is under development).
4747
2. Remove non-essential sample files and take care of GitHub-related files.
48-
3. Build JavaScript files and export to `assets/js/dist/`{: .filepath }, then make them tracked by Git.
48+
3. Build CSS/JS assets files and then make them tracked by Git.
4949
4. Automatically create a new commit to save the changes above.
5050

5151
### Installing Dependencies

_sass/main.bundle.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import 'dist/bootstrap';
2+
@import 'main';
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
---
33

4-
@import 'main';
4+
@import 'main
5+
{%- if jekyll.environment == 'production' -%}
6+
.bundle
7+
{%- endif -%}
8+
';
59

610
/* append your custom style below */

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
},
1414
"homepage": "https://github.com/cotes2020/jekyll-theme-chirpy/",
1515
"scripts": {
16-
"build": "npm run build:js",
16+
"build": "concurrently npm:build:*",
17+
"build:css": "purgecss -c purgecss.config.js",
1718
"build:js": "rollup -c --bundleConfigAsCjs --environment BUILD:production",
1819
"watch:js": "rollup -c --bundleConfigAsCjs -w",
19-
"lint:style": "stylelint _sass/**/*.scss",
20-
"lint:fix:style": "npm run lint:style -- --fix",
20+
"lint:scss": "stylelint _sass/**/*.scss",
21+
"lint:fix:scss": "npm run lint:style -- --fix",
2122
"test": "npm run lint:scss"
2223
},
2324
"dependencies": {
@@ -37,8 +38,10 @@
3738
"@semantic-release/changelog": "^6.0.3",
3839
"@semantic-release/exec": "^6.0.3",
3940
"@semantic-release/git": "^10.0.1",
41+
"concurrently": "^8.2.2",
4042
"conventional-changelog-conventionalcommits": "^7.0.2",
4143
"husky": "^9.0.11",
44+
"purgecss": "^6.0.0",
4245
"rollup": "^4.15.0",
4346
"rollup-plugin-license": "^3.3.1",
4447
"semantic-release": "^23.0.8",

0 commit comments

Comments
 (0)