Skip to content

Commit

Permalink
#53 updates for F# CS first
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Apr 15, 2024
1 parent e51af61 commit 2567767
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
41 changes: 26 additions & 15 deletions WebSharper.Templates/templates/ClientServer-FSharp/Site.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,41 @@ module Templating =
]

let Main ctx action (title: string) (body: Doc list) =
Content.Page(
Templates.MainTemplate()
.Title(title)
.MenuBar(MenuBar ctx action)
.Body(body)
.Doc()
)
Templates.MainTemplate()
.Title(title)
.MenuBar(MenuBar ctx action)
.Body(body)
.Doc()

module Site =
open WebSharper.UI.Html

open type WebSharper.UI.ClientServer

let HomePage ctx =
Templating.Main ctx EndPoint.Home "Home" [
h1 [] [text "Say Hi to the server!"]
div [] [client (Client.Main())]
]
Content.Page(
Templating.Main ctx EndPoint.Home "Home" [
h1 [] [text "Say Hi to the server!"]
div [] [client (Client.Main())]
]
//-:cnd:noEmit
#if RELEASE
,
Bundle = "home"
#endif
)

let AboutPage ctx =
Templating.Main ctx EndPoint.About "About" [
h1 [] [text "About"]
p [] [text "This is a template WebSharper client-server application."]
]
Content.Page(
Templating.Main ctx EndPoint.About "About" [
h1 [] [text "About"]
p [] [text "This is a template WebSharper client-server application."]
]
#if RELEASE
,
Bundle = "about"
#endif
)

[<Website>]
let Main =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<Compile Include="Site.fs" />
<Compile Include="Startup.fs" />
<Content Include="Main.html" CopyToPublishDirectory="Always" />
<None Include="package.json" />
<None Include="esbuild.config.mjs" />
<None Include="wsconfig.json" />
</ItemGroup>

Expand All @@ -21,4 +23,12 @@
<PackageReference Include="WebSharper.AspNetCore" />
</ItemGroup>

<Target Name="EnsureNodeModulesInstalled" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Release' ">
<Exec Command="npm install" />
</Target>

<Target Name="ESBuildBundle" AfterTargets="WebSharperCompile" Condition=" '$(Configuration)' == 'Release' ">
<Exec Command="node ./esbuild.config.mjs" />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readdirSync, cpSync } from 'fs'
import { build } from 'esbuild'

cpSync('./build/Content/WebSharper/', './wwwroot/Content/WebSharper/', { recursive: true });

const files = readdirSync('./build/Scripts/WebSharper/WebSharper.ClientServer.FSharp/');

files.forEach(file => {
if (file.endsWith('.js')) {
var options =
{
entryPoints: ['./build/Scripts/WebSharper/WebSharper.ClientServer.FSharp/' + file],
bundle: true,
minify: true,
format: 'iife',
outfile: 'wwwroot/Scripts/WebSharper/' + file,
globalName: 'wsbundle'
};

build(options);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"esbuild": "^0.19.9"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"$schema": "https://websharper.com/wsconfig.schema.json",
"project": "web",
"outputDir": "wwwroot"
"outputDir": "wwwroot",
"release": {
"outputDir": "build",
"preBundle": true
}
}

0 comments on commit 2567767

Please sign in to comment.