First release

This commit is contained in:
iko 2021-09-12 15:12:28 +03:00
parent c3878fb782
commit afcb48e7e2
Signed by untrusted user: iko
GPG Key ID: 82C257048D1026F2
3 changed files with 47 additions and 0 deletions

15
Readme.md Normal file
View File

@ -0,0 +1,15 @@
# GHCJS-optimizer
This is a simple nix wrapper that optimizes the js with [Google Closure Compiler](https://github.com/google/closure-compiler) and compresses text files with [zopfli](https://github.com/google/zopfli).
This is very simple and intended for a pretty narrow use case: it is intended for use with [haskell.nix](https://github.com/input-output-hk/haskell.nix) (but will probably work with other nix builders). It also only uses the `all.js` file, since it allows more room for optimization, and having one file in most cases will be better than loading multiple. This means that the default `index.html` generated by the stock builder will not work. I replace `index.html` with one that only uses `all.js`.
## Example
```nix
let ghcjs-optimizer = import ../ghcjs-optimizer { pkgs = nixpkgs; };
in ghcjs-optimizer hsPkgs.projectCross.ghcjs.hsPkgs.<your project>.components.exes.<your executable>;
```
I suggest you use [niv](https://github.com/nmattia/niv) for nix dependencies like this.

20
default.nix Normal file
View File

@ -0,0 +1,20 @@
{ pkgs ? null
, closurecompiler ? pkgs.closurecompiler
, zopfli ? pkgs.zopfli
, useZopfli ? true
, preserveHTML ? false
}:
input:
pkgs.runCommand "${input.name}-optimized"
{ } ''
shopt -s globstar
mkdir $out
cp ${if preserveHTML then "${input}/bin/*/index.html" else ./index.html} $out/index.html
chmod +w -R $out
${closurecompiler}/bin/closure-compiler --compilation_level ADVANCED --jscomp_off=checkVars --warning_level QUIET --js ${input}/bin/*/all.js --externs ${input}/bin/*/all.js.externs --js_output_file $out/all.js
${ if useZopfli then "${zopfli}/bin/zopfli $out/**/*.{js,css,json,html}" else "" }
''

12
index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
</body>
<script language="javascript" src="all.js"></script>
</html>