如何自动编译LESS到服务器上的CSS? [英] How to automatically compile LESS into CSS on the server?

查看:868
本文介绍了如何自动编译LESS到服务器上的CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的朋友设计师手动编译他的LESS文件,并上传它与Coda(远程站点)花费大量宝贵的时间。他问我:

Friend designer of mine was compiling his LESS file manually and uploading it with Coda (Remote Site) spending lots of precious time. He asked me:

是否可以自动检测Linux服务器上的文件更改,并立即编译?

Is it possible to automatically detect file change on the Linux server and compile without delay at all?

推荐答案

我制作了一个脚本并发布了细节:

I have made a script and I publish the details:



  • 任何能够进行远程编辑的编辑器都可以使用这个解决方案 - 代码, Sublime Text,Textmate

首先,您需要在服务器上安装npm在控制台中输入:

First, you need to install "npm" on the server by typing this into the console:

sudo apt-get install npm inotify-tools
sudo npm install -g less
sudo nano /usr/local/bin/lesscwatch

将以下内容粘贴到文件中:

Paste the following into the file:

#!/bin/bash
# Detect changes in .less file and automatically compile into .css
[ "$2" ] || { echo "Specify both .less and .css files"; exit 1; }
inotifywait . -m -e close_write | while read x op f; do.
    if [ "$f" == "$1" ]; then.
        lessc $f > $2 && echo "`date`: COMPILED";.
    fi
done

保存,退出,然后执行:

Save, exit, then execute:

sudo chmod +x /usr/local/bin/lesscwatch

你们都做完了。下一次你需要使用你的LESS文件,你需要打开终端(Coda有一个内置),转到文件的文件夹(使用cd),并执行:

You are all done. Next time you need to work with your LESS files, you will need to open terminal (Coda has a built-in), go to the folder of your file (using cd) and execute this:

lesscwatch main.less main.css

它将输出有关成功编译或错误的信息。享受。

It will output information about successful compilations or errors. Enjoy.

这篇关于如何自动编译LESS到服务器上的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆