Improved buildtime with esbuild
This commit is contained in:
parent
23f7160a5d
commit
89934be8d6
9 changed files with 9761 additions and 134 deletions
5
Makefile
5
Makefile
|
@ -13,8 +13,9 @@ frontend: frontend-format
|
||||||
cd frontend && elm make src/Main.elm --output=../assets/js/main.js
|
cd frontend && elm make src/Main.elm --output=../assets/js/main.js
|
||||||
|
|
||||||
frontend-produce: frontend-format
|
frontend-produce: frontend-format
|
||||||
cd frontend && elm make src/Main.elm --optimize --output=../assets/js/main.js
|
cd frontend && elm make src/Main.elm --optimize --output=../assets/js/tmp.js
|
||||||
uglifyjs assets/js/main.js --compress "pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe" | uglifyjs --mangle --output assets/js/main.js
|
esbuild assets/js/tmp.js --minify --target=es5 --outfile=assets/js/main.js
|
||||||
|
rm assets/js/tmp.js
|
||||||
|
|
||||||
frontend-format:
|
frontend-format:
|
||||||
elm-format frontend/src/Main.elm --yes
|
elm-format frontend/src/Main.elm --yes
|
||||||
|
|
File diff suppressed because one or more lines are too long
9714
assets/js/main.tmp.js
Normal file
9714
assets/js/main.tmp.js
Normal file
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,81 +0,0 @@
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf8">
|
|
||||||
<title>Main</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
background-color: #000000;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<script src="main.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script>
|
|
||||||
var app;
|
|
||||||
|
|
||||||
// call main with data from ./init.json and initialisation function
|
|
||||||
callWithServerData('./init.json', main, init)
|
|
||||||
|
|
||||||
// FUNCTIONS
|
|
||||||
|
|
||||||
// takes pertinent data and returns an app
|
|
||||||
// serverData : Object
|
|
||||||
// cookies : Object
|
|
||||||
function init(serverData, cookies) {
|
|
||||||
const flags = {...serverData, ...cookies};
|
|
||||||
|
|
||||||
app = Elm.Main.init({
|
|
||||||
flags: flags
|
|
||||||
});
|
|
||||||
|
|
||||||
app.ports.setStorage.subscribe(setStorage);
|
|
||||||
|
|
||||||
app.ports.refresh.subscribe(main);
|
|
||||||
}
|
|
||||||
|
|
||||||
// main 'loop'
|
|
||||||
// serverData : Object
|
|
||||||
// init : Function
|
|
||||||
function main(serverData, init) {
|
|
||||||
const cookies = localStorage.getItem('cookies') ? JSON.parse(localStorage.getItem('cookies')) : "";
|
|
||||||
init(serverData, cookies);
|
|
||||||
|
|
||||||
// XXX send test server data to getTestFromServer
|
|
||||||
// callWithServerData('./test.json', app.ports.getTestFromServer.send);
|
|
||||||
}
|
|
||||||
|
|
||||||
// passes the content of json at path to the function toCall
|
|
||||||
// path : String
|
|
||||||
// toCall : Function
|
|
||||||
function callWithServerData(path, toCall, ...args) {
|
|
||||||
fetch(path)
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (toCall === main) {
|
|
||||||
toCall(data, args[0]);
|
|
||||||
} else {
|
|
||||||
toCall(data, args);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error('Err ', err.message);
|
|
||||||
const data = "";
|
|
||||||
if (toCall === main) {
|
|
||||||
toCall(data, args[0]);
|
|
||||||
} else {
|
|
||||||
toCall(data, args);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// sets localStorage cookies to passed cookies value
|
|
||||||
// cookies : Object
|
|
||||||
function setStorage(cookies) {
|
|
||||||
localStorage.setItem('cookies', JSON.stringify(cookies));
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -133,7 +133,6 @@ type Msg
|
||||||
| UrlChanged Url.Url
|
| UrlChanged Url.Url
|
||||||
| TakeInput String
|
| TakeInput String
|
||||||
| NoInitFocus
|
| NoInitFocus
|
||||||
| ReceivedTest (Result D.Error Test)
|
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
|
@ -178,14 +177,6 @@ update msg model =
|
||||||
NoInitFocus ->
|
NoInitFocus ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
ReceivedTest result ->
|
|
||||||
case result of
|
|
||||||
Ok test ->
|
|
||||||
( { model | content = model.content ++ [ text "\nData got successfully" ] }, Cmd.none )
|
|
||||||
|
|
||||||
Err err ->
|
|
||||||
( { model | content = model.content ++ [ text <| "\n" ++ D.errorToString err ] }, Cmd.none )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- COMMANDS
|
-- COMMANDS
|
||||||
|
@ -199,6 +190,7 @@ type Command
|
||||||
| Hello
|
| Hello
|
||||||
| PromptCommand
|
| PromptCommand
|
||||||
| Theme
|
| Theme
|
||||||
|
| Todo
|
||||||
|
|
||||||
|
|
||||||
type alias Input =
|
type alias Input =
|
||||||
|
@ -236,6 +228,9 @@ parseInput input =
|
||||||
Just "theme" ->
|
Just "theme" ->
|
||||||
Ok Theme
|
Ok Theme
|
||||||
|
|
||||||
|
Just "todo" ->
|
||||||
|
Ok Todo
|
||||||
|
|
||||||
Just trimput ->
|
Just trimput ->
|
||||||
Err trimput
|
Err trimput
|
||||||
|
|
||||||
|
@ -289,6 +284,9 @@ runCommand model input =
|
||||||
Theme ->
|
Theme ->
|
||||||
runTheme model args
|
runTheme model args
|
||||||
|
|
||||||
|
Todo ->
|
||||||
|
( runTodo model args, Cmd.none )
|
||||||
|
|
||||||
Err "" ->
|
Err "" ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
@ -323,6 +321,7 @@ runHelp model args =
|
||||||
++ "\nfont manages font"
|
++ "\nfont manages font"
|
||||||
++ "\nprompt [UNFINISHED] manages prompt"
|
++ "\nprompt [UNFINISHED] manages prompt"
|
||||||
++ "\ntheme manages theme"
|
++ "\ntheme manages theme"
|
||||||
|
++ "\ntodo prints aspirations for the site"
|
||||||
]
|
]
|
||||||
|
|
||||||
Just "help" ->
|
Just "help" ->
|
||||||
|
@ -375,6 +374,9 @@ runHelp model args =
|
||||||
++ "\n pit - nearly black like the bottom of a pit"
|
++ "\n pit - nearly black like the bottom of a pit"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Just "todo" ->
|
||||||
|
[ text "\ntodo prints aspirations for the site" ]
|
||||||
|
|
||||||
Just string ->
|
Just string ->
|
||||||
wrongArgs Help 1 args
|
wrongArgs Help 1 args
|
||||||
|
|
||||||
|
@ -600,16 +602,6 @@ runPrompt model args =
|
||||||
saveModel { model | prompt = { oldPrompt | prompt = string } }
|
saveModel { model | prompt = { oldPrompt | prompt = string } }
|
||||||
|
|
||||||
|
|
||||||
runReset : Model -> List String -> ( Model, Cmd Msg )
|
|
||||||
runReset model args =
|
|
||||||
case List.head args of
|
|
||||||
Nothing ->
|
|
||||||
( model, Cmd.none )
|
|
||||||
|
|
||||||
Just _ ->
|
|
||||||
( model, Cmd.none )
|
|
||||||
|
|
||||||
|
|
||||||
runTheme : Model -> List String -> ( Model, Cmd Msg )
|
runTheme : Model -> List String -> ( Model, Cmd Msg )
|
||||||
runTheme model args =
|
runTheme model args =
|
||||||
case List.head args of
|
case List.head args of
|
||||||
|
@ -653,6 +645,29 @@ runTheme model args =
|
||||||
( { model | content = model.content ++ wrongArgs Theme 1 args }, Cmd.none )
|
( { model | content = model.content ++ wrongArgs Theme 1 args }, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
|
runTodo : Model -> List String -> Model
|
||||||
|
runTodo model args =
|
||||||
|
case List.head args of
|
||||||
|
Nothing ->
|
||||||
|
{ model
|
||||||
|
| content =
|
||||||
|
model.content
|
||||||
|
++ [ text <|
|
||||||
|
"\n--Frontend"
|
||||||
|
++ "\n- Implement colors throughout existing methods"
|
||||||
|
++ "\n- Implement something like neofetch"
|
||||||
|
++ "\n--Glue"
|
||||||
|
++ "\n--Backend"
|
||||||
|
++ "\n- Collect and store feedback in a database"
|
||||||
|
++ "\n- Get an SSL certificate"
|
||||||
|
++ "\n- Support https"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
Just _ ->
|
||||||
|
{ model | content = model.content ++ wrongArgs Todo 0 args }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- COMMAND ABSTRACTIONS
|
-- COMMAND ABSTRACTIONS
|
||||||
|
|
||||||
|
@ -691,6 +706,9 @@ wrongArgs command expected args =
|
||||||
|
|
||||||
Theme ->
|
Theme ->
|
||||||
"theme"
|
"theme"
|
||||||
|
|
||||||
|
Todo ->
|
||||||
|
"todo"
|
||||||
in
|
in
|
||||||
[ text
|
[ text
|
||||||
((if expected > List.length args then
|
((if expected > List.length args then
|
||||||
|
@ -728,6 +746,8 @@ cookiesKeptToString : CookiesKept -> String
|
||||||
cookiesKeptToString cookiesKept =
|
cookiesKeptToString cookiesKept =
|
||||||
"{ keepFont = "
|
"{ keepFont = "
|
||||||
++ boolToString cookiesKept.keepFont
|
++ boolToString cookiesKept.keepFont
|
||||||
|
++ "\n, keepPrompt = "
|
||||||
|
++ boolToString cookiesKept.keepPrompt
|
||||||
++ "\n, keepTheme = "
|
++ "\n, keepTheme = "
|
||||||
++ boolToString cookiesKept.keepTheme
|
++ boolToString cookiesKept.keepTheme
|
||||||
++ "\n}"
|
++ "\n}"
|
||||||
|
@ -747,20 +767,6 @@ port setStorage : E.Value -> Cmd a
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- gets from server and everything
|
|
||||||
|
|
||||||
|
|
||||||
port refresh : () -> Cmd a
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- for testing purposes: test.json on server
|
|
||||||
|
|
||||||
|
|
||||||
port receiveTestFromServer : (E.Value -> msg) -> Sub msg
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- JSON
|
-- JSON
|
||||||
|
|
||||||
|
|
||||||
|
@ -848,26 +854,13 @@ promptDecoder =
|
||||||
(D.at [ "prompt", "prompt" ] D.string)
|
(D.at [ "prompt", "prompt" ] D.string)
|
||||||
|
|
||||||
|
|
||||||
type alias Test =
|
|
||||||
{ message0 : String
|
|
||||||
, message1 : String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
testDecoder : D.Decoder Test
|
|
||||||
testDecoder =
|
|
||||||
D.map2 Test
|
|
||||||
(D.field "message0" D.string)
|
|
||||||
(D.field "message1" D.string)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- SUBSCRIPTIONS
|
-- SUBSCRIPTIONS
|
||||||
|
|
||||||
|
|
||||||
subscriptions : Model -> Sub Msg
|
subscriptions : Model -> Sub Msg
|
||||||
subscriptions model =
|
subscriptions _ =
|
||||||
receiveTestFromServer (D.decodeValue testDecoder >> ReceivedTest)
|
Sub.none
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -876,7 +869,7 @@ subscriptions model =
|
||||||
|
|
||||||
view : Model -> Browser.Document Msg
|
view : Model -> Browser.Document Msg
|
||||||
view model =
|
view model =
|
||||||
Browser.Document "andrew.r3tic.net"
|
Browser.Document "elmskell"
|
||||||
[ toUnstyled <| viewBody model ]
|
[ toUnstyled <| viewBody model ]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
elmInputs = [
|
elmInputs = [
|
||||||
pkgs.elmPackages.elm
|
pkgs.elmPackages.elm
|
||||||
pkgs.elmPackages.elm-format
|
pkgs.elmPackages.elm-format
|
||||||
pkgs.uglify-js
|
pkgs.esbuild
|
||||||
];
|
];
|
||||||
haskellInputs = [
|
haskellInputs = [
|
||||||
pkgs.stack
|
pkgs.stack
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue