Forum > Pas2JS

HowTo: Compile app with Closure Compiler

(1/1)

ps:
"The Closure Compiler is a tool for making JavaScript download and run faster. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls."

https://developers.google.com/closure/compiler

We need little modification to our compiled javascript file .

1. Add window['rtl'] = rtl; to end of our compiled JS file
2. Create externs.js file

On Windows:

FILE: closure-footer.js

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  window['rtl'] = rtl;
FILE: externs.js

--- Code: Javascript  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---/** @interface */function ControlsAndConstants() {}/** @type {number} */ControlsAndConstants.prototype.run; FILE: compile.bat

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type closure-footer.js >> app.jsjava -jar closure-compiler-v20200517.jar --compilation_level SIMPLE --js app.js --js_output_file app-min.js
Note: Compilation level ADVANCED is not supported.

d-_-b:

--- Quote ---Note: Compilation level ADVANCED is not supported.
--- End quote ---

Which is sad because it the best compiler/transpiler for js out there, used by other languages like clojurescript.

Thanks for testing it with SIMPLE, baby steps, before one run, i believe.

lainz:
Remember that these compilers are not perfect, I usually get JavaScript broken with these tools, so try it with care.

ps:
Closure Compiler is amazing (esp. with ADVANCED), but there is problem. See this: https://bugs.freepascal.org/view.php?id=37114

lainz:
Yes, it's good. But anyways remember testing everything once compiled... things may fail.

Navigation

[0] Message Index

Go to full version