-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge JS + enable minification + Lighthouse
- Loading branch information
1 parent
5bc9bb7
commit 9e4039e
Showing
9 changed files
with
574 additions
and
504 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters