WebAssembly, Emscripten and for compilation. tools Javascript I have two news for you: good and bad. Good news— epoch of JavaScript compilation has already started. Bad news — we aren’t ready for this epoch yet. Really? Maybe you’ve seen (“The Birth & Death of JavaScript” by ). this conference talk Gary Bernhardt Shortly, the main idea of this talk is that — browsers will become a new OSs, JS will become a new C language, the software will migrate into the browser. Yes, this epoch has already started after Chrome OS, , Emscripten and WebAssembly. Because Electron app is equivalent to the browser that works as a desktop app. It’s a good first step before web will migrate to web: Electron Why since Electron? Before all desktop apps can work in the browser, we can try to run a single desktop app on top of the browser. What’s the problem with Electron? The main issue with Electron is simple: Electron is Flash for the desktop( ). great article about Electron For example, I have Slack, Atom, and 3 other apps built with Electron installed on my Mac. It equals to 5 Chromium browsers. WebAssembly, Emscripten, and LLVM _design - WebAssembly Design Documents_github.com WebAssembly/design I’m sure you’ve heard about . WebAssembly But if you want to use you . How many developers are with C/C++? WebAssembly need to know C or C++ frontend familiar Personally, I don’t know such developers in real life. Right now we can compile C/C++ code to Wasm in 2 ways: Compile with Emscripten. Compile with LLVM. Installation guide is here. Emscripten _emscripten - Emscripten: An LLVM-to-JavaScript Compiler_github.com kripken/emscripten Emscripten makes native code immediately available on the Web. One of the purposes was to . But currently, JavaScript is one of the most popular languages. It runs inside our , it runs on , it runs on the ( ). JS too. Emscripten ’s port existed huge C/C++ codebase to the Web browsers mobile platforms server Node codebase is huge JS -> WebAssembly Personally, I was searching for any tool that can translate JS to l to C/C++ or .And… I didn’t find any such tools. anguage that can be translated asm.js But you can find a tool to translate to JS. Almost always this tool exists. It proofs that JS codebase maybe . JS code can be generated with , , and other languages. <your-favorite-language/> the biggest codebase ever Java Python : The language is based on the OCaml’s backend and was developed to generate JS. OCaml bytecode can be translated into C code. It means that Reason (maybe) allows you to write both WebAssembly and JS. Interesting idea Reason Another approach is to compile JS into . Theoretically, that can provide JS compilation into It’s a crazy idea, but it will be great. LLVM bytecode native code and WebAssembly. Small note: JS can be generated from almost every language, but you can generate WebAssembly(that will interact with JS in the browser) only with languages that can be compiled into LLVM bytecode. But instead of writing C code it will be better to somehow translate JS into WebAssembly. Tools that “compile” your JS: Enclose Compile your Node.js project into an executable _enclose - Compile your Node.js project into an executable_github.com igorklopov/enclose There were two versions of Enclose: free and proprietary. Free version could bundle only five files.Also, it looks like Now the on . It was the first attempt to “compile” JS. Enclose is deprecated. project owner works Pkg Pkg Package your Node.js project into an executable _pkg - Package your Node.js project into an executable_github.com zeit/pkg Recent attempt to “compile” JS.How does it work? just puts 30MB Node binaries into the executable. So even code like generates a big file. Pkg const a = 5 From node-compiler docs(comparison table): hacked API's dynamically in order to access in-package files. uses JSON to store in-package files. Pkg fs.* Pkg Use cases: Make a demo version of your app. Make a cross-compiled executable. Personally, I’m sure that more suitable name for Pkg is Enclose 2 :) Main developer of Pkg is Igor Klopov: repo’s pulse here. . And you can check commit history uses devdependency . Pkg eslint-config-klopov Nexe 🎉 create a single executable out of your node.js apps _nexe - 🎉 create a single executable out of your node.js apps_github.com nexe/nexe Yet another attempt to compile JS. There is no official info how it exactly works, but that (like and ). after a small research, I figured out Nexe downloads Node binaries Pkg Enclose Problems: Nexe doesn’t support Node native modules. Nexe doesn’t support dynamic require statements. Nexe use browserify (Is it bad? ). I guess that it’s just not modern. But only in the master branch. You can find dev branch here. Node-Compiler Compiling your Node.js application into a single executable with dynamic require and all fs.* API support. _node-compiler - Compiling your Node.js application into a single executable with dynamic require and all fs.* API…_github.com pmq20/node-compiler recommends itself as a better replacement for Pkg and Nexe. As you can see . Node-compiler this tool bundles your app with node binaries (I’m not sure, there is no info about how it works) Also, it’s strange to find a Node.js repo in project repo, isn’t it? Small summary: looks like it’s not maintained. Enclose === ( _The Return of the Igor Klopov)_ <sarcasm> **//** Pkg Enclose 2.0: </sarcasm> stores Node.js repo in repo. <sarcasm> Node-Compiler </sarcasm> is developing, but not so actively. Nexe All these projects don’t compile JS, they just pack your code with Node binaries. But because you can pack your code in executable. they are still great for some purposes Compilation with JS engines Can we compile JS with V8/Chakra/SpiderMonkey? . For example, we can take unoptimized compiled (not “JIT-ed”) code from the engine. Yes, we can. Theoretically Unoptimized native code is less efficient than JIT-ed optimized code. No, we can’t. Every JS engine is a very complicated, confusing system that has own architecture and own features. Maybe. If you ask someone about how the browser works, you’ll see that this developer knows only common facts about browsers. And it’s … . Because not all programmers know . scary how the system (that executes their code) works Conclusion. must be . Electron revised Many frontend developers because can’t use WebAssembly don’t have a C/C++ background. There isn’t any tool to translate JS into another language. JS code can be generated from programming language. almost any Tools that can exist, but they into your file. make executable file put Node binaries are very and might be Browsers complicated better explained to developers. WebAssembly may become a compiled form of JavaScript. Maybe, JS is the new C language? The Modern C for the modern world. Github: Twitter: Mail: https://github.com/Metnew https://twitter.com/coldlinecall vladimirmetnew@gmail.com