简体   繁体   English

F#到JavaScript编译器的F#项目模板

[英]F# Project template for an F# to JavaScript compiler

I developed an F# to JavaScript (and to other dynamically typed languages) compiler. 我开发了一个F#到JavaScript (和其他动态类型的语言)编译器。 The compiler by itself is powerful, in the sense it is able to translate many F# constructs, on the other hand it is not so user-friendly. 编译器本身功能强大,从某种意义上说,它能够翻译许多F#构造,但另一方面,它也不是那么友好。 You still have to use a command-line executable to translate the project into JavaScript code. 您仍然必须使用命令行可执行文件将项目转换为JavaScript代码。

This is user-unfriendly for many reasons, one of them is debugging. 由于许多原因,这是用户不友好的,其中之一是调试。

So, I would like to create a project template (with basic directory structure) that would allow a programmer to write the code as if it was a normal F# project, then when he clicks the green "run" button the compilation process should start and finally a browser should open with a web page running the resulting JavaScript code. 因此,我想创建一个项目模板(具有基本的目录结构),该模板将允许程序员像正常的F#项目一样编写代码,然后单击绿色的“运行”按钮,则编译过程应该开始,并且最后,浏览器应打开一个运行结果JavaScript代码的网页。 Anyone who has ever used Websharper or Pit knows what I'm talking about. 使用过Websharper或Pit的任何人都知道我在说什么。

Of course, in case the translation is done to some other language, I would like the "run" button to behave differently. 当然,如果翻译成其他语言,我希望“运行”按钮的行为有所不同。 Basically, another template should do the job. 基本上,另一个模板应该可以完成这项工作。

So my question is: are there any alternatives to pre- and post-compilation phases? 所以我的问题是:编译前和编译后阶段是否有其他选择? I precise that the compiler can also be used as a library instead of a binary executable. 我精确地指出,编译器也可以用作库而不是二进制可执行文件。

Any reference to useful documentation is appreciated. 任何对有用文档的引用都将受到赞赏。

The FunScript project (F# to JavaScript compiler) has example projects that employ a launcher (written by Tomas Petricek) that compiles the marked modules, starts a minimal web server and opens the default web page in the browser. FunScript项目(F#到JavaScript编译器)的示例项目使用启动器 (由Tomas Petricek编写),该启动器编译标记的模块,启动最小的Web服务器并在浏览器中打开默认网页。

FunScript Canvas sample: FunScript Canvas示例:

[<ReflectedDefinition>]
module Program

open FunScript

let main() =
  let canvas = Globals.document.getElementsByTagName_canvas().[0]
  canvas.width <- 1000.
  canvas.height <- 800.
  let ctx = canvas.getContext_2d()
  ctx.fillStyle <- "rgb(200,0,0)"
  ctx.fillRect (10., 10., 55., 50.);
  ctx.fillStyle <- "rgba(0, 0, 200, 0.5)"
  ctx.fillRect (30., 30., 55., 50.)

do Runtime.Run(directory="Web")

Where Runtime.Run does the work. Runtime.Run在哪里工作。

See: https://github.com/ZachBray/FunScript/blob/master/Examples/Shared/Launcher.fs 参见: https : //github.com/ZachBray/FunScript/blob/master/Examples/Shared/Launcher.fs

For info on building F# project templates Dan Mohl has built a number of web templates using SideWaffle: http://bloggemdano.blogspot.co.uk/2013/12/simpleweb-and-servicestack-templates.html 有关构建F#项目模板的信息,Dan Mohl使用SideWaffle构建了许多Web模板: http ://bloggemdano.blogspot.co.uk/2013/12/simpleweb-and-servicestack-templates.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM