I have been trying to use the Kotlin -> js compiler by following this tutorial.
When I run kotlinc-js --help, then the help text mentions the following:
-kjsm Generate kjsm-files (for creating libraries)
What is a kjsm file?
A kjsm-file is a Kotlin JavaScript Meta file (see KotlinJavaScriptMetaFileType).
Such a file appears to be used to provide meta data for native JavaScript objects so that the Kotlin compiler can type-check things and so that an IDE can provide code completion, etc. e.g. If you look in kotlin-js-library-1.0.6.jar you will find, among other kjsm-files, a Window.kjsm file which defines the Window Web API available in web browsers.
You would want to generate your own kjsm-files whenever you are creating a library so that your interfaces can be used by the compiler/IDE in modules which depend on your Kotlin JavaScript library.
Related
I am reading
To leverage one of the many existing libraries written in JavaScript, use package:js. If a TypeScript type definition file exists for a JavaScript library (see DefinitelyTyped for more info), you can use the js_facade_gen tool to generate Dart code for that library. from https://webdev.dartlang.org/guides/web-programming.
I am curious how convert javascript library to dart file in the example https://github.com/google/chartjs.dart. I guess there are two steps: 1, generate TypeScript type definition file (ts file) from the javascript library; 2, Use js_facade_gen to convert ts file to dart.
I hope get more details. but the document is lacking. Any hints welcomed. Thanks
There is no way to convert JavaScript to Dart automatically.
package:js allows you to call JavaScript from Dart in Dart browser apps.
I've recently created a JavaScript library using Google's Closure Compiler: https://github.com/bvaughn/task-runner
I intend for this library to be used by applications that also require the full Closure Library, and so I want the built version of my library (Task Runner) not to include a subset of Closure Library. If Task Runner includes a subset of Closure Library, and another application includes the full Closure Library, a race condition will exist between which loads Closure last (last in wins). It also bloats the size of the Task Runner file.
However I'm having trouble. If I don't require any of the Closure library classes, Task Runner builds fine (obviously). However if I require something (goog.dom for instance) then my "compiled" JavaScript file also includes a portion of the Closure library. Is there a way to tell the Closure Compiler to leave certain JavaScript files/modules/whatever out of the built result?
FWIW, the Plovr experimental-exclude-closure-library option seems to somewhat describe the functionality I'm looking for.
On the surface what you are asking makes no sense. You want to depend on/use code from Closure-library, but not include it in your output. This isn't really possible nor how the library and compiler function together.
There is a rather small list of primitive functions defined in Closure-library that are completely removed/replaced when compiled with Closure-compiler. goog.require and goog.provide are the two most prominent of those.
For the vast majority of the Closure-Library, if you use or depend on a class, method or object that specific code will appear in the compiled output. And because that library code itself may depend on other parts of the library, even more code may be included in the compiled result.
The difference between using Closure-compiler with Closure-library as compared to more traditional JavaScript libraries is that ONLY the parts of the code determined to be called and used are included in the output. This is much more granular than a simple file inclusion - prototypes, variables, constants, etc will all be excluded because the compiler can determine that they are never used.
Distributing a Library
If you are building a library which depends on Closure-library, you have two options.
Distribute a compiled/built version
You would compile your library using Closure-library; exporting any public API methods and properties. Others who utilize your library with Closure-compiler or Closure-library will need to use an externs file and include your library AFTER compilation.
Distribute your library as source
You would simply distribute your library source code. Others would goog.require your library as part of their source and build process. If Closure-library is used in both projects, it will only be included once in the build process.
There is no hybrid approach where you compile your code but exclude Closure-library. This violates the principle that all of the source code will be compiled simultaneously.
You can peruse my Geolocation-marker library to see an example. I provide a compiled standalone version of the code for use, but the uncompiled source can also be included in other projects which use Closure-library.
I'm trying to make use of a Haxe library in Javascript. Since I already have a project written in Javascript, porting that to Haxe + using the given Haxe library isn't really a solution I'm ready to take at the moment.
Is there a way I can just compile the library from it's Haxe source folder to a JS file that I can then include in my <script> tags and refer to in my project? If I'm not mistaking, when a Haxe project normally compiles, it only includes the classes actually used in your project (correct?) - therefore I need some kind of tool or compiler options that will include all the classes in a given directory.
I would assume packages will get namespaced into Javascript objects at that point.
In case this helps, the library I'm looking to transcompile is Nape (Physics engine written in Haxe).
Looks like I found a way!
From FlashDevelop, create a new Haxe project (for JS).
Then, add a reference to the library that you wish to compile, either by:
Finding it in your Haxe install directory/haxe/lib/name_of_library/version_of_library.
Or, simply by adding the library name in your project settings, under Libraries (as shown in the picture below).
Third (most important step), add --macro include('your_library_root_packagename') in the Additional Compiler Options (replace with your library's top-level package name, obviously!)
I believe that if you have a library consisting of many top-level packages, you would need to enumerate several of those --macro compiler options. In my case I just needed the one.
Finally, CTRL+ENTER... wait for it to transcompile and Voila!
You have a Library in Javascript format!
I wrote my first library in dart. Now I want to make use of it in a website. My idea was to compile all necessary dart code of my lib and its dependencies into one javascript file that has a useful "global" API. As I understand this I would also write this API in dart and compile it altogether to javascript but I fail to see how this is done. The https://www.dartlang.org/tools/dart2js/ wasn't particular helpful to me.
To give a simplified example: The library is a generic parser controlled by a grammar. A parse-tree is build from some input file and a grammar. Think of it like:
ParseTree parse(File input, File grammar);
So in the resulting javascript I want to have this available in some form so one could write e.g.
var tree = MyParserLib.parse("path/to/input.file", "my.gramamar.file");
Usually you build your entire app at once. Building distinct parts or libraries to JS and using the output in another app is not (yet?) well supported.
I'm learning how to use Magento e-commerce system, and I'm reading its documentation, but I don't understand some term, a "pre-compiled JavaScript library". What do they mean by that? How can JavaScript code be compiled?
The web downloader for upgrading and installing Magento without the
use of SSH (covered in Chapter 2). • js—The core folder where all
JavaScript code included with the installation of Magento is kept. We
will find all pre-compiled libraries of JavaScript here.
Source:
http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento_s_base_structure
I do not know what Magento e-commerce uses, but I know what JavaScript Compilers are.
Pre-Compiled JavaScript is not practical as the various JavaScript interpreters will have their own method of compiling. Therefore, when most people talk about Compiling JavaScript, they are usually referring Minified JavaScript.
However, the latest minifiers go way beyond. A good example is Google Closure Compiler Advanced Mode. It is related to Google Closure Library and Tools, but is well designed even when used by itself.
There is an Online Demo of Closure Compiler.
It is called a Compiler because it is more than a minifier and the name JavaScript Compiler is not used for anything else. For example: This code
function hello(name) {
alert('Hello, ' + name);
}
hello('New user');
compiles to alert("Hello, New user"); in advanced mode. Single-use functions are removed, variable names are shortened, and even re-used.
It is very thorough. Simple mode assumes that there might be other JavaScript involved. in which case it would preserve the hello function. Advanced mode assumes that there is only a single JavaScript file, or that it is properly exported.
The one thing that keeps this from really being compiled is that it is not bytecode like compiled C or Java would be. It still has to be compiled at run-time like Perl.
Magento has an configuration option in the admin at
System -> Configuration -> Developer -> JavaScript Settings
named Merged Javascript Files.
When this setting is on, Magento will take all the javascript files it knows about, "compile" them to a minified version to product smaller files sizes, and then combine all the javascript files into a single javascript file. This way, instead of opening multiple network connections to download multiple files, Magento will open a single network connection to open one file.
So, when the documentation says that folder contains the pre-compiled versions, it means that's where the individual javascript files are stored, and where the files are loaded from when Merged Javascript Files
The term compilation comes from Computer Science. A compiler takes source code, and transforms it from one language into another language.
Traditionally, it's meant taking code from a higher level language (C, .NET, Java, etc.), and transforming it into the machine code (assembly code) that's understood by the computer chip. However, the term is generic and more modern usage includes taking the source code written in one language (Javascript) and transforms it into a different form (minified javascript).