3

What is the sense of the mod.js file which transcrypt is generating when compiling javascript code from the Python code? I understand that it seems to hold the pure routine compiled to Javascript which one has written in Python without any extensions or whatsoever.

Could it be used directly in the html file by embedding it into the code? If yes how could it be done? This would give quite a short code which had been written orginally in Python - which makes it easier to develop and to read. I have experimented with it and you can even mix Javascript elements with Python code directly - if you know what you are doing. I can post an example if it is wished.

bunkus
  • 975
  • 11
  • 19

1 Answers1

1

The .mod.js file is the javascript-only representation of a module. It is produced during compilation, much like a .obj file with a C/C++ compiler.

You can make a javascript-only distribution of a module by only supplying the .mod.js file in the __javascript__ subfolder of your module folder. An example of this in the distro is the itertools module at:

https://github.com/QQuick/Transcrypt/tree/master/transcrypt/modules/itertools

It ONLY has JS code, no Python code. This is called a JS-only module. If Transcrypt can't find a .py at the right import location, it'll look for a .mod.js file. This is rather underdocumented at the time.

If you want to use something as short as the .mod.js file in your html, take a look at units:

http://www.transcrypt.org/docs/html/special_facilities.html#transcrypt-s-unit-mechanism-and-creating-native-javascript-component-frameworks

You'll need at least one unit holding the runtime (ca 40k minified). All other units are very small components (typically < 1k), even slightly smaller than the .mod.js files. They can be loaded selectively (but not yet dynamically unless using a trick) using the unit loader as shown in the example.

Jacques de Hooge
  • 6,750
  • 2
  • 28
  • 45