Developer forum

Forum » CMS - Standard features » Less not working with javascript compiler. Is it due to a missing mimetype on the server?

Less not working with javascript compiler. Is it due to a missing mimetype on the server?

Hans Ravnsfjall
Hans Ravnsfjall
Reply

I have set it up like this

 <link rel="stylesheet/less" type="text/css" href="/Files/Templates/Designs/SSTemplate/css/styles.less" />
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js" ></script>
   

I believe this is what is described here:

http://lesscss.org/

 

Is it because of a missing mimetype for less on the server, or do i have to do something else?

/Hans


Replies

 
Nicolai Pedersen
Reply

I dould'nt know... I have no experience with browser compiled less.

You might want to look through the docs here: http://lesscss.org/usage/#using-less-in-the-browser

BR Nicolai

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Hans,

Yes, you have to register the mime type in web.config (configuration > system.webServer > staticContent):

<remove fileExtension=".less" />
<mimeMap fileExtension=".less" mimeType="text/plain" />

Note: If you have also added the http handler for dotless in web.config then that will process the less file before it is downloaded and processed by less.js
You can read more about the differences between less.js and dotless here: https://github.com/dotless/dotless/wiki/Less-js-differences

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Anyone had success with this? Seems adding the MimeType makes it possible to load the file directly, but when called through the pageview, it gives an errror saying unsupported mimtype.

How do you all work with less, scss etc. on livesolutions?

/Hans

 

 
Claus Kølbæk
Claus Kølbæk
Reply

Hey Hans

I always compile to css before using it, wouldn't that solve your problem?

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hej Claus

Yes, it would. Just trying to save a bit of time and hassle in in the longrun, so we donĀ“t have to compile to CSS untill at the very end, just before the website goes live.

Our setup is currently, we use Visual Studio Code to edit the files directly on the server  - via FTP.

But maybe there is some smarter/better way to achieve the same results? What is your setup? Do you work on the solution locally, or do you have some automatic setup where you auto upload the css? We are trying to avoid having to upload the CSS file everytime to see the changes. Maybe there is a better/smarter solution to our objectives?

/Hans

 

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

BTW. we got it to work using the Javascript compiler, with great help from the Dynamicweb support. Took a while to get the correct Mimetype.

/Hans

 
Claus Kølbæk
Claus Kølbæk
Reply

Hey Hans

There are many ways to Rome :)

But if you open it as a website in visual studio through FTP, then you could fx use a visual studio extension like webcompiler (https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebCompiler), then everytime you edit a less file, it compiles a new css file (You prob. have to open generated file and save it aswell, for it to be transfed to the ftp.) - So the only extra work is saving a file more, whenever you make an edit.

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Thanx Claus

Will try that if the current setup turns out to have som unforeseen stumbling blocks

/Hans

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hey Hans,

Have you made it work in Visual Studio Code with Javascript compiler?

Can you share the solution?

We have struggled for a while with editing directly on the server but we eneded up configuring the solution locally in order to use Visual Studio Webcompiler.

I would rather use Visual Studio code and edit files directly on the server.

Thank you,

Adrian

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Adrian

We use VSCode with the "FTP-Simple" extension to connect to the server, and "LESS intellisense" extension to handle the LESS stuff in VSCode

The MimeType on the server has be the type txtx/css (Claus in the Dynamicweb Support helped set this up on the solution for us)

In the head of our Master template, we have this:

 <link rel="stylesheet/less" type="text/css" href="css/styles.less" />
           
           <script>
  less = {
    env: "development",
      useFileCache: false,
  };
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js" ></script>

 

Seems to work flawlessly (if there are no CSS errors). Eg a misspelling like "!impotrant" will make it fault, but then again - that helps make sure the final CSS is "pure".

 

Feel free to ask, if there are any Questions.

 

/Hans

 

 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Hans,

Thank you very much.

I will try on my end.

Regards,

Adrian

 

You must be logged in to post in the forum