5

Is it possible to use websharper as a drop-in replacement for javascript without the additional complexity of sitelets or ASP.NET?

For example, can I compile the following websharper library to a .js file and call the hello() function from within a javascript script block in my html?

namespace WebSharperLib

open IntelliFactory.WebSharper

module HelloWorld =
  [<JavaScript>]
  let hello () =
    IntelliFactory.WebSharper.JavaScript.Alert("Hello World")
Oenotria
  • 1,692
  • 11
  • 24

1 Answers1

6

You can indeed do something like that. The solution i found is as following :

  • Create a WebSharper library project in VS
  • Paste the code in your example
  • Generate the solution
  • Copy the last line of the solution generation (where it runs websharper) and run it in powershell/console just adding the option

    -js name of your js file

The thing is, this way you don't have any of the compiled dependencies. I guess you can get them if you make a full project and go grab the compiled js output there.

Tt seems to me WebSharper is not made to be used this way, but rather as a full package.

If you just want F# compilation to Javascript, there is Pit that is made exactly for that purpose, so i suggest you try that first.

raph.amiard
  • 2,755
  • 2
  • 20
  • 23
  • 1
    It sounds like he's probably looking for something like Pit. – Onorio Catenacci Oct 12 '12 at 15:10
  • 2
    I am looking for something like Pit except it's full of bugs :) – Oenotria Oct 12 '12 at 15:22
  • If you copy the web sharper command and put it in a post-build script, and manage to include websharper's stdlib permanently you can probably have a good worklow with websharper and visual studio. Just takes some initial set up :) – raph.amiard Oct 12 '12 at 21:18
  • Thanks, after a bit of messing around I've finally gotten this to work satisfactorily. In order to trigger the javascript to execute you need something like this: `` – Oenotria Oct 27 '12 at 00:22