mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 17:37:51 +01:00
add minify js :3
This commit is contained in:
parent
9a26c2a332
commit
f852fc7410
1 changed files with 43 additions and 30 deletions
|
@ -67,12 +67,12 @@ module.exports = function (app, config, renderTemplate) {
|
|||
});
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const CleanCSS = require("clean-css");
|
||||
const fs = require("fs");
|
||||
const CleanCSS = require("clean-css");
|
||||
|
||||
const cssDir = "./css/";
|
||||
const cssDir = "./css/";
|
||||
|
||||
app.get("/css/:id", (req, res) => {
|
||||
app.get("/css/:id", (req, res) => {
|
||||
const filePath = path.join(cssDir, req.params.id);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
res.status(404).send("File not found");
|
||||
|
@ -94,13 +94,26 @@ module.exports = function (app, config, renderTemplate) {
|
|||
if (req.params.id.endsWith(".js")) {
|
||||
res.redirect("/static/" + req.params.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/static/:id", (req, res) => {
|
||||
app.get("/static/:id", (req, res) => {
|
||||
if (req.params.id.endsWith(".css")) {
|
||||
res.redirect("/css/" + req.params.id);
|
||||
} else if (req.params.id.endsWith(".js")) {
|
||||
const filePath = path.join(html_location, req.params.id);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
res.status(404).send("File not found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Minimize the JavaScript file
|
||||
const js = fs.readFileSync(filePath, "utf8");
|
||||
const minimizedJs = require("uglify-js").minify(js).code;
|
||||
// Serve the minimized JavaScript file
|
||||
res.header("Content-Type", "text/javascript");
|
||||
res.send("// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" + " " + minimizedJs + " " + "// @license-end");
|
||||
} else {
|
||||
res.sendFile(req.params.id, { root: html_location });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue