最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Running Less.js on C#Javascript.netV8 - Stack Overflow

programmeradmin2浏览0评论

I'm trying to run less.js in a C# application. I tried running the default distro using JavaScript but I'm getting window is undefined error. I think that is caused due to this not being run in a browser but on a JS engine. Is there any workaround / any pointers to resources that can help?

I'm trying to run less.js in a C# application. I tried running the default distro using JavaScript but I'm getting window is undefined error. I think that is caused due to this not being run in a browser but on a JS engine. Is there any workaround / any pointers to resources that can help?

Share Improve this question edited Jan 17, 2018 at 4:27 Oliver Bock 5,1255 gold badges46 silver badges65 bronze badges asked Jul 14, 2010 at 16:01 DogbertDogbert 223k42 gold badges417 silver badges415 bronze badges 4
  • IIRC, less.js is the module that allows you to use somewhat different syntax in your stylesheets. If you don't have a page to style...? – Robert Harvey Commented Jul 14, 2010 at 16:04
  • I'm trying to convert a less file to css programatically. Should have mentioned that above. – Dogbert Commented Jul 14, 2010 at 16:07
  • Accept, or ment if the answers is unsatisfactorily – Lasse Espeholt Commented Jul 22, 2010 at 8:25
  • It looks like less.js (looking at the source) should allow you to pass in an undefined window reference, can you tell us what line the window is undefined is happening on? – Bob Fincheimer Commented Jul 22, 2010 at 12:59
Add a ment  | 

3 Answers 3

Reset to default 8 +100

You should probably run .Less instead. If I understand correctly, you are trying to run less.js on the server through a Javascript interpreter. Why not just skip the interpreter and run LESS conversion using all .NET code? Way less pain and overhead.

Less.js indicates that it's intended to be run under Node.js. Because it sounds like you're writing a .NET app, why not see if Node will help you?

This is more a guess: according to the documentation (I have never worked with Javascript) the following is valid:

// Initialize the context
JavascriptContext context = new JavascriptContext();

// Setting the externals parameters of the context
context.SetParameter("console", new SystemConsole());
context.SetParameter("message", "Hello World !");
context.SetParameter("number", 1);

// Running the script
context.Run("var i; for (i = 0; i < 5; i++) console.Print(message + ' (' + i + ')'); number += i;");

// Getting a parameter
Console.WriteLine("number: " + context.GetParameter("number"));

Maybe you should set the window as a parameter to the context ala this:

context.SetParameter("window", new YourWindow());

And insure the window your providing have the same attributes/methods/etc. as the standard browser window.

Addition You could try and implement a simple window which just writes to the console whenever some function is called on it. Unless of cause, Javascript.Net gives you a window wrapper (does not seem like it though)

发布评论

评论列表(0)

  1. 暂无评论