Comments (7)
@stutteringp0et — hmm I'll need to think about what would be the best way to accomplish this. Anyone else have any ideas?
from v8js.
I also found envjs, but that's geared toward rhino, and again - I'm not sure how to load it other than stringing all of the files together and introducing it as a string.
I'll start with a overview of what I was trying to accomplish (done now), followed by what I did in V8Js to accomplish it.
The CSS interpreter less.js has only one official parser - their javascript interpreter. Unofficial interpreters exist for PHP and .net - but neither can fully realize the full feature set of less.js because they can't interpret JS directly - so if an input file uses JS in any of the settings - that file will fail in the unofficial interpreters.
So, my goal was to use V8Js to give less.js the environment it requires to execute serverside. The problem was that less.js, upon load, scans the DOM for scripts to process - halting operation in V8Js immediately - because there's no DOM.
So, in V8Js, I executed this string first:
window = this;window.location={href:"file://",port:""};document={getElementsByTagName:function(){return []}};
less.js gets the responses it's expecting (even though there is still no DOM), allowing me to call it as a class to process strings instead of the content of dom elements.
Still, I'm sure it would be beneficial to have a full DOM in V8Js, I'm just not guru enough to figure out how to do it.
from v8js.
If you only need LESS compilation then it should be possible without any DOM.
LESS can be used with node.js and without DOM support. However, it seems to "require" other files in order to initialise the compiler.
I've just submitted a pull request that will add CommonJS "require" support to V8Js. I think this will get you a step closer to having LESS work in V8Js.
from v8js.
I already have it running. I used the line of code I posted earler to
fool less into thinking it had a DOM.
The LESS server side script has specific detection for nodejs, rhino and
one other that I can't remember offhand. I spent some time looking up
the objects that rhino and node make available and it was less trouble
to go back to the client script and fake a DOM.
from v8js.
Sorry, my bad - I didn't pick up that you had this working. Great to hear that you found a solution.
from v8js.
@stutteringp0et You might also want to check out https://github.com/andreasgal/dom.js/ it emulates the DOM in plain JS.
from v8js.
@stutteringp0et, @christiaan https://github.com/fgnass/domino is a fork of dom.js that removes mozilla-specific proxy support, and is better maintained in general. I'll probably try to add this to v8js at some point (or else expose the PHP.dom package to JS, haven't decided yet).
from v8js.
Related Issues (20)
- Trying to compile with php8 branch on ubuntu 22, getting error: could not determine libv8 version (v8 compiled succesfully) HOT 3
- Dynamic Properties deprecation in PHP 8.2 HOT 4
- Broken build on PHP 8.0.x HOT 2
- Segmentation fault - possibly another GC issue? HOT 7
- Compromise between FORCE_ARRAY and standard setup HOT 8
- sandbox error with v8 11.1.277.13 HOT 1
- libv8 must be version 9.0 or greater (using dockerfile) HOT 1
- Issue running make in ubuntu 22.04 HOT 2
- windows php 8.1
- compile error with g++ 13: error: expected unqualified-id before '&' token
- With wich version of V8 this php library work ? HOT 4
- Error installing on debian 11
- This LIB is very hard to install ! HOT 14
- PROHIBITS_OVERWRITING removed from V8 and causing V8Js compile error. HOT 1
- V8Js 3.0.0 HOT 1
- Is the latest recommended release 2.1.1 or 2.1.2? HOT 4
- Do I have permission to refactor this? HOT 3
- Compilation error: "no matching function for call to 'v8::ObjectTemplate::SetAccessor" HOT 6
- Linux arm64 support? HOT 3
- Is there an official installation tutorial for the v8js extension? HOT 1
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 v8js.