Skip to content

Commit

Permalink
add CSS minfier that executes automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
tazz4843 committed Sep 8, 2023
1 parent a51eb0d commit b4b35ee
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 16 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/pages-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
fetch-depth: 0

# Setup Node.js and NPM
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
name: Setup Node.js
with:
node-version: 16

# Update NPM
- name: Update NPM
run: sudo npm install -g npm
run: npm install -g npm

# Install build deps
- name: Install build deps
Expand All @@ -40,6 +40,10 @@ jobs:
base-url-path: https://scripty.org
drop-html-extension: true

# Shrink CSS
- name: Shrink CSS
run: node minify.js

# Download minifier program and untar it to /tmp
- name: Download minifier
run: |
Expand Down Expand Up @@ -67,4 +71,4 @@ jobs:
github_token: ${{ secrets.ACCESS_TOKEN }}
publish_dir: ./out
cname: scripty.org
exclude_assets: '.github,node_modules,lib,_sass,_javascript'
exclude_assets: '.github,node_modules,lib,_sass,_javascript,minify.js,package.json,package-lock.json,README.md'
26 changes: 26 additions & 0 deletions minify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

// Minify CSS using purgecss
//
// Load all HTML files in the same directory and subdirectories, then
// load all CSS rules from the /css/main.css file,
// remove all unused rules and finally save the result to the /css/main.min.css file.


const PurgeCSS = require('purgecss').PurgeCSS;

const purgeCSS = new PurgeCSS();

const purgeCSSConfig = {
content: ['./**/*.html'],
css: ['./css/main.css'],
output: './css/main.min.css',
};

purgeCSS.purge(purgeCSSConfig).then(result => {
// write to file
require('fs').writeFileSync(purgeCSSConfig.output, result[0].css);
console.log('CSS minified successfully!');
}).catch(err => {
console.log(err);
});
169 changes: 160 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"bulma": "^0.9.3",
"npm-run-all": "^4.1.5",
"postcss-cli": "^9.1.0",
"purgecss": "^5.0.0",
"sass": "^1.51.0"
},
"homepage": "https://github.com/jgthms/bulma-start#readme",
Expand All @@ -62,10 +63,8 @@
"css-deploy": "npm run css-build && npm run css-postcss",
"css-postcss": "postcss --use autoprefixer --output css/main.css css/main.css",
"css-watch": "npm run css-build -- --watch",
"deploy": "npm run css-deploy && npm run js-build",
"js-build": "babel _javascript --out-dir lib",
"js-watch": "npm run js-build -- --watch",
"start": "npm-run-all --parallel css-watch js-watch"
"css-minify": "node ./minify.js",
"start": "npm-run-all --parallel css-watch css-minify"
},
"version": "0.0.5"
}

0 comments on commit b4b35ee

Please sign in to comment.