Comments (2)
Hacked a workaround until this is resolved. In my index.html
, instead of putting the main.js
in a <script>
, I create it dynamically, and then in script.onload
, I check to make sure Elm
is defined, otherwise I change the scripts src
to main.js?tries=1
etc. The downside is this requires a hack to change elm-live's start.js
's parseUrl
to ignore querystrings for the target:
//index.html, in a <script> tag, where callback is whatever logic for initializing elm you use
let tries = 0;
const mainName = "/main.js";
function loadScript(url, callback)
{
var head = document.head;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
const try_again = () => {
script.remove();
let new_url = mainName + "?____tries___="+tries;
console.log("trying again for", new_url)
loadScript(new_url, callback);
tries += 1;
}
script.onload = (args, second_args) => {
if (typeof Elm === "undefined") {
try_again();
} else {
return callback()
}
};
// Fire the loading
head.appendChild(script);
}
//elm-live/lib/src/start.js
function parseUrl (pathname, model) {
if (pathname.startsWith(model.target)) {
console.log("overriting pathname to ", model.target);
pathname = model.target;
}
...
}
Maybe there's a better way of getting elm-live to see that main.js?anythingatall
is still a request for main.js
, but this works for now, even if it only stops the partial file errors, and not the errors about the file length mismatch.
from elm-live.
I've made some changes to elm-live's build.js
to hack around this issue. It seems to be some sort of issue with either elm fighting with another sub process of elm make in runElm
, so a solution I'm using is setting a global variable to true
when its building, and false
when its done.
const GLOBALS = {};
GLOBALS['isBuilding'] = false;
const setIsBuilding = () => { GLOBALS['isBuilding'] = true; }
const setIsNoLongerBuilding = () => { GLOBALS['isBuilding'] = false; }
then runElm turns into
const runElm = model => Async((reject, resolve) => {
const wasBuilding = isItBuilding();
setIsBuilding();
...
if (!wasBuilding ) {
proc = spawn(model.elm, ['make', '--report=json', ...model.elmArgs])
} else {
reject(`already ${chalk.bold('building')}, so just exiting instead.`);
return;
}
...
proc.on('error', function (error) {
setIsNoLongerBuilding();
if (error.code === 'ENOENT') {
...
}
proc.on('exit', function (status) {
setIsNoLongerBuilding();
...
}
...
return wasBuilding; //not sure if this is necessary, since its in a callback as it is
}
This effectively just kills elm-live when it tries to build while elm-live's already in the process of building once.
A better solution would either:
- put the error message I reject with into
messages.js
- or, add some action in
init.js
and resolve() instead of reject()ing, and then handling that action down the pipe, so elm-live wouldn't crash. Everything I tried to hack together still ended up with a JS error in Chrome withmain.js
being half-written to, or a HTTP error with a length mismatch (probably a symptom of the same issue, just sooner up the chain)
For me, I just run elm-live in a powershell loop and its good enough for now (appears to work with hot-reloading too, which is a nice bonus)
while ($true) { elm-live elmliveargs "--" elmmakeargs }
from elm-live.
Related Issues (20)
- [QUESTION] Plans for tests
- elm-live crash when a file is not found instead responding with a 404 HOT 4
- Support multiple proxies
- Option to ignore self signed certificates in proxied services
- elm-live adds "undefined" text to the document HOT 4
- Reload snippet not inserted when using --proxy-host HOT 1
- file watcher does not work on mounted docker volumes HOT 2
- Request for Release that bumps `http-proxy` to >=1.18.1 HOT 4
- Not refreshing when specifying Elm file in folder. Only watches /src folder for changes. HOT 1
- "-- --output=elm.js" not working as expected in PowerShell HOT 1
- Only certain known filetypes are served
- Proxying does not work HOT 7
- Yarn: Output In Wrong Location when using -- --output='file.js' HOT 2
- Support multiple elm apps (mains)
- anchors seem broken in documentation
- elm-live renders empty page, elm reactor renders correctly HOT 1
- Hot-reload mode completely blank HOT 1
- Serving .js files as HTML leading to a blank page HOT 2
- reload code not served through nginx reverse proxy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm-live.