less.watch() called in production mode FIX && clearInterval @ unwatchless.watch() hívása production módban FIX && clearInterval @ unwatch
Recently I did a pull request into less.js, but the project owner (cloudhead) have already got 80+other requests so I publish here one solution for an issue in this framework:
When you call less.watch()
in production environment or with the hash mark -> it just does not work. Feature or bug dunno. But:
Many people trying to do this:
<script type="text/javascript" src="less-1.2.2.js"></script> <script type="text/javascript"> // <![CDATA[ less.env = "development"; less.watch(); // ]]> </script>
but they do not realize that less.env
line is ignored (because less.js loaded itself right before that line), and that variable is auto set up based on your URL (localhost
/127.0.0.1
,file:///
,etc). Which is not always useful.
For example I work on localhost with a http://projects.local/...
host name so there the less.watch()
wont work.
I added a bit code to the browser.js
.
https://github.com/zsitro/less.js/commit/696c9ec034b373c63e7e734d7ebb9b0be04e8ca0
EFFECT: less.watch()
can be called from hash or from script
tag even in production env.
Now this will function as follows:
<script type="text/javascript" src="less-1.2.2.js"></script> <script type="text/javascript"> // <![CDATA[ //less.env = "development"; ITS JUST DUMB less.watch(); // ]]> </script>
Also fixed: missing clearInterval
@ less.unwatch()
. Its weird that less.js does not kill the timer, but check the less.watchMode
true/false in the loop :D
Hope you guys like it.
Anyway, after using less.js I switched to lessPHP. Its much faster and reliable, than the javascript compiler. I will write about it later.Nemrég küldtem egy pull request-et a less.js repójába, de a projekt gazdája (cloudhead) már így is 80+ másik kéréssel van elmaradva. Szóval úgy döntöttem, itt publikálom az egyik issue-val kapcsolatos megoldást:
Amikor meghívod a less.watch()
metódust a production környezetben, vagy a # karakterrel URL-ből -> nem fog működni. Hogy ez szándékos, vagy bug? Nem tudom, de:
Sokan próbálják így inicializálni a less.js-t:
<script type="text/javascript" src="less-1.2.2.js"></script> <script type="text/javascript"> // <![CDATA[ less.env = "development"; less.watch(); // ]]> </script>
de nem veszik figyelembe, hogy a less.env
sor nem fog végrehajtódni (mert ezt a less-x.js betöltésekor automatikusan feldolgozza magának előtte egy sorral), valamint, hogy ennek a változónak az értéke az URL-edből (localhost
/127.0.0.1
,file:///
,etc) automatikusan lesz eldöntve. Ez nem mindig célszerű, nem mindig hatékony.
Például én localhost-on dolgozok a http://projects.local/...
host alias-szal, ahol a less.watch()
nem fog lefutni.
Megoldásként a browser.js
ezt a folyamatot befolyásoló részéhez adtam hozzá pár sor kódot.
https://github.com/zsitro/less.js/commit/696c9ec034b373c63e7e734d7ebb9b0be04e8ca0
Eredmény: less.watch()
hívható # taggel, vagy egyenesen script
tagból production környezetben is.
Vagyis:
<script type="text/javascript" src="less-1.2.2.js"></script> <script type="text/javascript"> // <![CDATA[ //less.env = "development"; ITS JUST DUMB less.watch(); // ]]> </script>
Továbbá javításra került: hiányzó clearInterval
a less.unwatch()
hívása után. Elég furi, hogy a less.js nem öli le a timert, csak egy less.watchMode
true/false értéket nézeget továbbra is a loop-ban :D.
Másik fejlemény, hogy pár napos less.js használat után váltottam a lessPHP-re, ami sokkal gyorsabb és hatékonyabb munkát biztosít. Erről később fogok írni..