Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStorm: How do I setup LESS to output to CSS directory with file watcher?

Tags:

How do, using File Watchers in PHPStorm do I set up LESS file watchers output path to do this:

I want:

/project/path/less/dir/file.less

to output to:

/project/path/css/dir/file.css

or

/project/path/less/file2.less

to output to:

/project/path/css/file2.css

I'm not seeing a clear way to make this happen with the Output Path macros in PHPstorm. With the FileDirRelativeToProjectRoot macro, I'm able to get the path to the current directory, but there is no clear way to replace /less with /css in the path.

like image 491
aaronp Avatar asked Apr 11 '13 23:04

aaronp


People also ask

How do I set up file watcher?

Creating a File WatcherIn the Settings/Preferences dialog ( Ctrl+Alt+S ), click File Watchers under Tools. The File Watchers page opens showing a list of File Watchers that are already configured in this project and in the IDE. and choose the predefined template from which you want to create a File Watcher.

How can I use SCSS?

To start, create a folder with two folders inside, CSS and images. Then inside the CSS folder create a file with the Sass extension – in my case it's style. scss. Then open it and the file will be detected right away.

What are file watchers?

File Watcher is an IntelliJ IDEA tool that allows you to automatically run a command-line tool like compilers, formatters, or linters when you change or save a file in the IDE.


3 Answers

See my related answer for JADE file watcher, I believe it would be the same for LESS.

The trick is to use $FileDirPathFromParent(dir)$ macro:

$ProjectFileDir$/css/$FileDirPathFromParent(less)$ will produce /project/path/css/dir/ for a file located in /project/path/less/dir/ directory.

like image 186
CrazyCoder Avatar answered Dec 16 '22 11:12

CrazyCoder


I want to compile one less file from

sites/all/themes/bic/res/less/style.less to sites/all/themes/bic/res/css/style.css

Here's what I did

enter image description here

So the Arguments I used is: --no-color $FileName$ ../css/$FileNameWithoutExtension$.css

This will produce: /usr/local/bin/lessc --no-color blogs.less ../css/blogs.css at phpstorm console, and works fine.

I might miss something. Anyway, I tried both "--no-color $FileName$ $ProjectFileDir$/sites/all/themes/bic/res/css/$FileDirPathFromParent(less)$" and "--no-color $FileName$ $ProjectFileDir$/sites/all/themes/bic/res/css/$FileDirPathFromParent(less)$$FileNameWithoutExtension$.css". Neither of them work for me. So just post my solution here, which might help some people who has the same trouble with me..

like image 31
smiletrl Avatar answered Dec 16 '22 11:12

smiletrl


Just change Output Path to Refresh to:

../css/$FileNameWithoutExtension$.css

Update:

In the new version of LESS you should reverse your slashes in Path you specify. So it should be:

..\css\$FileNameWithoutExtension$.css

like image 24
Andrew Bogdanov Avatar answered Dec 16 '22 09:12

Andrew Bogdanov