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
|
||||
|
||||
frontend-produce: frontend-format
|
||||
cd frontend && elm make src/Main.elm --optimize --output=../assets/js/main.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
|
||||
cd frontend && elm make src/Main.elm --optimize --output=../assets/js/tmp.js
|
||||
esbuild assets/js/tmp.js --minify --target=es5 --outfile=assets/js/main.js
|
||||
rm assets/js/tmp.js
|
||||
|
||||
frontend-format:
|
||||
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
|
||||
| TakeInput String
|
||||
| NoInitFocus
|
||||
| ReceivedTest (Result D.Error Test)
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
|
@ -178,14 +177,6 @@ update msg model =
|
|||
NoInitFocus ->
|
||||
( 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
|
||||
|
@ -199,6 +190,7 @@ type Command
|
|||
| Hello
|
||||
| PromptCommand
|
||||
| Theme
|
||||
| Todo
|
||||
|
||||
|
||||
type alias Input =
|
||||
|
@ -236,6 +228,9 @@ parseInput input =
|
|||
Just "theme" ->
|
||||
Ok Theme
|
||||
|
||||
Just "todo" ->
|
||||
Ok Todo
|
||||
|
||||
Just trimput ->
|
||||
Err trimput
|
||||
|
||||
|
@ -289,6 +284,9 @@ runCommand model input =
|
|||
Theme ->
|
||||
runTheme model args
|
||||
|
||||
Todo ->
|
||||
( runTodo model args, Cmd.none )
|
||||
|
||||
Err "" ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
@ -323,6 +321,7 @@ runHelp model args =
|
|||
++ "\nfont manages font"
|
||||
++ "\nprompt [UNFINISHED] manages prompt"
|
||||
++ "\ntheme manages theme"
|
||||
++ "\ntodo prints aspirations for the site"
|
||||
]
|
||||
|
||||
Just "help" ->
|
||||
|
@ -375,6 +374,9 @@ runHelp model args =
|
|||
++ "\n pit - nearly black like the bottom of a pit"
|
||||
]
|
||||
|
||||
Just "todo" ->
|
||||
[ text "\ntodo prints aspirations for the site" ]
|
||||
|
||||
Just string ->
|
||||
wrongArgs Help 1 args
|
||||
|
||||
|
@ -600,16 +602,6 @@ runPrompt model args =
|
|||
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 args =
|
||||
case List.head args of
|
||||
|
@ -653,6 +645,29 @@ runTheme model args =
|
|||
( { 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
|
||||
|
||||
|
@ -691,6 +706,9 @@ wrongArgs command expected args =
|
|||
|
||||
Theme ->
|
||||
"theme"
|
||||
|
||||
Todo ->
|
||||
"todo"
|
||||
in
|
||||
[ text
|
||||
((if expected > List.length args then
|
||||
|
@ -728,6 +746,8 @@ cookiesKeptToString : CookiesKept -> String
|
|||
cookiesKeptToString cookiesKept =
|
||||
"{ keepFont = "
|
||||
++ boolToString cookiesKept.keepFont
|
||||
++ "\n, keepPrompt = "
|
||||
++ boolToString cookiesKept.keepPrompt
|
||||
++ "\n, keepTheme = "
|
||||
++ boolToString cookiesKept.keepTheme
|
||||
++ "\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
|
||||
|
||||
|
||||
|
@ -848,26 +854,13 @@ promptDecoder =
|
|||
(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 : Model -> Sub Msg
|
||||
subscriptions model =
|
||||
receiveTestFromServer (D.decodeValue testDecoder >> ReceivedTest)
|
||||
subscriptions _ =
|
||||
Sub.none
|
||||
|
||||
|
||||
|
||||
|
@ -876,7 +869,7 @@ subscriptions model =
|
|||
|
||||
view : Model -> Browser.Document Msg
|
||||
view model =
|
||||
Browser.Document "andrew.r3tic.net"
|
||||
Browser.Document "elmskell"
|
||||
[ toUnstyled <| viewBody model ]
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
elmInputs = [
|
||||
pkgs.elmPackages.elm
|
||||
pkgs.elmPackages.elm-format
|
||||
pkgs.uglify-js
|
||||
pkgs.esbuild
|
||||
];
|
||||
haskellInputs = [
|
||||
pkgs.stack
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue