Skip to content

Commit

Permalink
Port standalone from old build system
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Oct 31, 2023
1 parent 9648c11 commit e02898b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 33 deletions.
69 changes: 59 additions & 10 deletions src/Fable.Build/Standalone.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,60 @@ open Build.Utils
open BlackFox.CommandLine
open System.IO
open Build.FableLibrary
open Fake.IO

let private projectDir = Path.Resolve("src", "fable-standalone")

let private buildDir = Path.Combine(projectDir, "temp")

let private distDir = Path.Combine(projectDir, "dist")

let build () =
let private buildWorker (minify: bool) =

let fableArgs =
CmdLine.empty
|> CmdLine.appendRaw "src/Worker"
|> CmdLine.appendPrefix "--outDir" (buildDir </> "worker")
|> CmdLine.appendPrefix "--lang" "javascript"

Command.Fable(fableArgs, workingDirectory = projectDir)

Command.Run(
"npx",
CmdLine.empty
|> CmdLine.appendRaw "rollup"
|> CmdLine.appendRaw (buildDir </> "worker" </> "Worker.js")
|> CmdLine.appendPrefix "-o" (buildDir </> "worker" </> "bundle.js")
|> CmdLine.appendPrefix "--format" "iife"
|> CmdLine.toString,
workingDirectory = projectDir
)

Command.Run(
"npx",
CmdLine.empty
|> CmdLine.appendRaw "esbuild"
|> CmdLine.appendRaw (buildDir </> "worker" </> "bundle.js")
|> CmdLine.appendRaw "--bundle"
|> CmdLine.appendRaw $"""--outfile={(distDir </> "worker.min.js")}"""
|> CmdLine.appendRaw "--format=iife"
|> CmdLine.appendIf minify "--minify"
|> CmdLine.toString,
workingDirectory = projectDir
)

let fableLibraryDist = (distDir </> "fable-library")

Directory.ensure fableLibraryDist

// Copy Fable library to dist folder
Shell.copyRecursive
(Path.Resolve("temp", "fable-library"))
fableLibraryDist
true
|> ignore

let build (minify: bool) =

let fableArgs =
CmdLine.concat [
Expand Down Expand Up @@ -42,8 +88,8 @@ let build () =
CmdLine.empty
|> CmdLine.appendRaw "rollup"
|> CmdLine.appendRaw (buildDir </> "Main.js")
|> CmdLine.appendPrefix "-o" (distDir </> "bundle.js")
|> CmdLine.appendPrefix "--format" "umd"
|> CmdLine.appendPrefix "-o" (buildDir </> "bundle.js")
|> CmdLine.appendPrefix "--format" "esm"
|> CmdLine.appendPrefix "--name" "__FABLE_STANDALONE__"
|> CmdLine.toString,
workingDirectory = projectDir
Expand All @@ -53,19 +99,22 @@ let build () =
"npx",
CmdLine.empty
|> CmdLine.appendRaw "esbuild"
|> CmdLine.appendRaw (distDir </> "bundle.js")
|> CmdLine.appendRaw (buildDir </> "bundle.js")
|> CmdLine.appendRaw "--bundle"
|> CmdLine.appendRaw $"""--outfile={(distDir </> "bundle.js")}"""
|> CmdLine.appendRaw $"""--outfile={(distDir </> "bundle.min.js")}"""
|> CmdLine.appendRaw "--format=esm"
|> CmdLine.appendRaw "--platform=node"
|> CmdLine.appendRaw "--minify"
|> CmdLine.appendRaw "--overwrite"
|> CmdLine.appendIf minify "--minify"
|> CmdLine.toString,
workingDirectory = projectDir
workingDirectory = projectDir
)

buildWorker minify

let handle (args: string list) =
let minify = args |> List.contains "--no-minify" |> not
let isWatch = args |> List.contains "--watch"
let skipFableLibrary = args |> List.contains "--skip-fable-library"

BuildFableLibraryJavaScript().Run(skipFableLibrary)

build ()
build minify
3 changes: 2 additions & 1 deletion src/fable-standalone/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Override .gitignore to include the `dist` folder
test/
src/**/bin/
src/**/obj/
src/**/obj/
temp/
12 changes: 2 additions & 10 deletions src/fable-standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
"type": "module",
"name": "fable-standalone",
"version": "3.2.11",
"main": "./dist/FABLE_STANDALONE.umd.js",
"module": "./dist/FABLE_STANDALONE.es.js",
"exports": {
".": {
"import": "./dist/FABLE_STANDALONE.es.js",
"require": "./dist/FABLE_STANDALONE.umd.js"
}
},
"main": "./dist/bundle.min.js",
"description": "Fable compiler",
"keywords": [
"fable",
Expand All @@ -28,7 +21,6 @@
"homepage": "https://github.com/fable-compiler/Fable#readme",
"devDependencies": {
"esbuild": "^0.19.5",
"rollup": "^4.1.5",
"vite": "^4.5.0"
"rollup": "^4.1.5"
}
}
12 changes: 0 additions & 12 deletions src/fable-standalone/vite.config.ts

This file was deleted.

0 comments on commit e02898b

Please sign in to comment.