Skip to content

Commit

Permalink
Merge JS + enable minification + Lighthouse
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Mar 5, 2024
1 parent 5bc9bb7 commit 9e4039e
Show file tree
Hide file tree
Showing 9 changed files with 574 additions and 504 deletions.
489 changes: 0 additions & 489 deletions assets/analyzer.js

This file was deleted.

505 changes: 498 additions & 7 deletions assets/script.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.light-theme {
.light {
--background: #FFF;
--header-bg: #8be0c0;
--dialog-bg: #EEE;
Expand Down Expand Up @@ -35,8 +35,8 @@ body {
}

button {
padding: 5px 8px;
font-size: 16px;
padding: 6px 8px;
font-size: 16.5px;
border: none;
border-radius: 7px;
cursor: pointer;
Expand Down
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ module.exports = [
globals: global
},
files: ["**/*.js"],
ignores: ["eslint.config.js", "assets/jszip.min.js"],
ignores: ["eslint.config.js", "minify.js", "assets/jszip.min.js"],
plugins: {
unicorn,
sonarjs,
Expand All @@ -240,7 +240,7 @@ module.exports = [
...globals.node
}
},
files: ["eslint.config.js"],
files: ["eslint.config.js", "minify.js"],
plugins: {
unicorn,
sonarjs,
Expand Down
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<link href="./assets/images/icon-192x192.png" rel="apple-touch-icon" sizes="192x192">

<link rel="stylesheet" href="./assets/style.css">
<script src="./assets/analyzer.js"></script>
<script src="./assets/script.js"></script>
<script src="./assets/jszip.min.js" async></script>
</head>
Expand Down
50 changes: 50 additions & 0 deletions minify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fsPromises = require("node:fs").promises
const UglifyJS = require("uglify-js")

const nameCache = {}
const defaultOptions = {
compress: {
passes: 2,
unsafe: true,
unsafe_Function: true,
unsafe_math: true,
unsafe_proto: true,
unsafe_regexp: true
}
}

const minifyFile = async (path, options = {}) => {
const filename = path.split("/").pop()
const result = UglifyJS.minify({
[path]: await fsPromises.readFile(path, "utf8")
}, {
sourceMap: {
root: "https://pack-analyzer.pages.dev/assets/",
filename,
url: filename + ".map"
},
warnings: "verbose",
parse: {
shebang: false
},
nameCache,
mangle: true,
...defaultOptions,
...options
})

if (result.error) throw result.error
if (result.warnings && result.warnings.length > defaultOptions.compress.passes) console.log(path, result.warnings)

if (process.env.MINIFY_ENABLED) {
await fsPromises.writeFile(path, result.code)
await fsPromises.writeFile(path + ".map", result.map)
}
}

async function main() {
await minifyFile("./assets/script.js", {
module: false
})
}
main()
14 changes: 14 additions & 0 deletions package-lock.json

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

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
"type": "git",
"url": "https://github.com/DEVTomatoCake/Pack-Analyzer.git"
},
"scripts": {
"minify": "node minify.js"
},
"dependencies": {
"uglify-js": "^3.17.4"
},
"devDependencies": {
"@html-eslint/eslint-plugin": "^0.23.1",
"@html-eslint/parser": "^0.23.0",
Expand Down
3 changes: 1 addition & 2 deletions serviceworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ self.addEventListener("install", event => {
const fallbackCache = await caches.open("fallback" + version)
fallbackCache.addAll([
"/assets/style.css",
"/assets/script.js",
"/assets/analyzer.js"
"/assets/script.js"
])
})())
})
Expand Down

0 comments on commit 9e4039e

Please sign in to comment.