Skip to content

Commit

Permalink
Minify css
Browse files Browse the repository at this point in the history
  • Loading branch information
NeeEoo committed Oct 1, 2024
1 parent 73df014 commit abb490e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
24 changes: 24 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"remarkable": "^2.0.1"
},
"devDependencies": {
"clean-css": "^5.3.3",
"sass": "^1.79.1"
}
}
7 changes: 6 additions & 1 deletion src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var tools = require('./pages/tools/tools.build.js');
var apiDocs = require('./pages/apiDocs.build.js');
var indexPage = require('./pages/index.build.js');

var { copyDir, fixHtmlRefs, parseTemplate, compileSass } = require('./utils.js');
var { copyDir, fixHtmlRefs, parseTemplate, compileSass, setGlobals, getGlobals } = require('./utils.js');

var isFullBuild = process.argv.includes('--full');
process.argv = process.argv.filter(arg => arg != '--full');
Expand All @@ -17,6 +17,11 @@ process.argv = process.argv.filter(arg => arg != '--watch');
var isFirstRun = process.argv.includes('--first-run');
process.argv = process.argv.filter(arg => arg != '--first-run');

var isRelease = process.argv.includes('--release') || isFullBuild;
process.argv = process.argv.filter(arg => arg != '--release');

setGlobals({isFullBuild, isWatch, isFirstRun, isRelease});

hljs.registerLanguage('haxe', haxeformat);

var pageDir = process.argv[2] || "./";
Expand Down
24 changes: 24 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ var path = require("path");
var hljs = require('highlight.js');
var fs = require('fs');
var sass = require('sass');
var CleanCSS = require('clean-css');

var isFullBuild = false;
var isWatch = false;
var isFirstRun = false;
var isRelease = false;

function setGlobals(data) {
isFullBuild = data.isFullBuild;
isWatch = data.isWatch;
isFirstRun = data.isFirstRun;
isRelease = data.isRelease;
}

function getGlobals() {
return {isFullBuild, isWatch, isFirstRun, isRelease};
}

function fixPath(url) {
return url.replaceAll(path.sep, path.posix.sep);
Expand Down Expand Up @@ -166,10 +183,17 @@ function compileSass(file, dest) {
}
}]
});
if(isRelease) {
result.css = new CleanCSS({
level: 2
}).minify(result.css).styles;
}
fs.writeFileSync(dest, result.css);
}

module.exports = {
setGlobals: setGlobals,
getGlobals: getGlobals,
fixPath: fixPath,
fixHtmlRefs: fixHtmlRefs,
copyDir: copyDir,
Expand Down

0 comments on commit abb490e

Please sign in to comment.