-
Notifications
You must be signed in to change notification settings - Fork 63
Elm Reactor + External CSS #138
Comments
Maybe some of the solution(s) here would help you in the meantime, in the absence of the specific feature you ask for? |
Thanks for pointing that out @jvoigtlaender , I'll give them a try, but it is good to see that other people had similar needs in the past |
I drop this here, it could be nice if in addition to type alias Document =
{ title : String
, metas : List Meta
, scripts : List Script
, stylesheets : List Stylesheet
, body : List Html
, className : String
} People are constantly asking on the ML or here how to achieve this, it must reflect a real need. |
I'm surprised that something simple like having a bootstrap/semantic UI css along side elm has taken me half an hour to get to this point with no results...
|
@fluxxu loving it |
I am trying to learn elm, coming only with basic experience with js Html and CSS. I don't want to work with less, scss or sass or other tools like webpack. Trying to solve the problem of including external CSS in my elm project I keep getting search results about elm-reactor and elm-css. For people like me, it would be just great to have and example minimal as html with one external CSS file. |
@oz123 You could use workaround like this. Add <html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="styles.css"><!-- Put your styles in folder with index.html -->
</head>
<body>
<div style="width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #9A9A9A; font-family: 'Source Sans Pro';">
<div style="font-size: 3em;">Building your project!</div>
<img src="/_reactor/waiting.gif">
<div style="font-size: 1em">With new projects, I need a bunch of extra time to download packages.</div>
</div>
</body>
<!-- Fonts and external JS and styles are available, I've put Ace for example -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.4/ace.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.4/theme-chrome.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.4/worker-lua.js"></script>
<!-- Put the name of your app here (my sources place in `src` forder) -->
<script type="text/javascript" src="/_compile/src/YourApp.elm"></script>
<!-- Removes splash and starts elm app. -->
<script type="text/javascript">
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
runElmProgram();
</script>
</html> Now, open it with reactor :) |
@deniskolodin, wow! Thanks for the quick response. So this will also work with |
@oz123 I use different for testing and production. But minimal changes you need: <!-- Head is the same -->
<body>
<div id="my-app"></div>
</body>
<!-- Fonts and external JS and styles are available -->
<!-- Your source after making -->
<script type="text/javascript" src="YourApp.js"></script>
<!-- Removes splash and starts elm app. -->
<script type="text/javascript">
var node = document.getElementById('my-app');
var app = Elm.YourApp.embed(node);
</script> |
Suggestion: could we have support for a |
I tried elm a year ago, had this problem too. Now i just came back in the elm irc channel and i see people who still have this exact same problem. Makes me believe urgency is high on this one ^^ |
@flip111 You can use the following in the meantime: for development, for production |
@MeinAccount. Thx i will forward your solution when i see someone else asking about it again. Perhaps it's worthwhile too include it in the reactor documentation or website |
@flip111 I'd suggest a section on using a custom HTML-file. That's useful for including CSS, JS as well as custom HTML-Code. The other option would be the suggested |
- Shift everything around in main.go - Use shortened json result as response to front-end for development - Follow advice from github on how to embed custom css when using elm-reactor elm-lang/elm-reactor#138 (comment)
Starting with the advice in #138 (comment), I made a bootstrap repo that (for me) is the simplest way to serve custom CSS while developing. Golang is required, however. Maybe someone will find it helpful. |
Here's the solution I use to keep using Elm Reactor while messing with external CSS, flags and ports from the Javascript side: <!doctype html>
<meta charset=utf-8>
<title>a title</title>
<link href=/bundle.css rel=stylesheet>
<body></body>
<script src="/_compile/Main.elm"></script> <!-- this will fail in production -->
<script src="/elm-bundle.js"></script> <!-- this will fail in development -->
<script>
var app
var flags = {}
try {
app = Elm.App.fullscreen(flags)
/* app.ports is now available */
} catch (e) {
// this will run in case there are compile errors:
var stylesheets = document.querySelectorAll('link')
for (var i = 0; i < stylesheets.length; i++) {
stylesheets[i].parentNode.removeChild(stylesheets[i])
}
runElmProgram()
}
</script> |
I've been compiling down to index.html and using a separate stylesheet but it would be nice to run something like Will see if I can do this, this is a very useful feature. Just some ideas on how to implement this:
|
Having Html.node "link" [ Html.Attributes.rel "stylesheet", Html.Attributes.href "style.css" ] [] as another child returned from |
@mathphreak Where do you put style.css locally? |
@stoivo Same directory as my |
Is any progression? |
I'm using the following function in my code. I have to use a trick to avoid flickering. Is there any downside to this technique? It generates a script that adds the stylesheet link into the header.
|
Hi,
I'd like to know if it is possible to use the reactor(by using I mean keep it recompiling the code at every change, debug and time-travel) with an external CSS being loaded with the Elm file. Let's say my entire project is just a single Elm file(or centralized on a main Elm file) and I want to use the reactor with an external CSS source, is this possible ?
My current "solution" is to use grunt and make it recompile the code but obviously I lose the debug and time-travel abilities from reactor, I'm willing to implement this myself, just want to collect some feedback first and maybe some initial guidance.
My idea is to simply add a
<link>
reference in the header of the auto generated HTML based on some commmand line argument, something like that:It would be up to the person to generate this single CSS containing everything he needs but I believe this wouldn't be an issue(at least not so big as having to choose between CSS and debug+time-travel).
Thanks
The text was updated successfully, but these errors were encountered: