Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to autoprefix css files generated by less, in Webstorm?

Tags:

webstorm

less

I've got Webstorm 7 (on Win7) compiling my .less files into minified css with sourcemaps (using lessc on nodejs v0.10.26, run from a File Watcher in Webstorm), and I can then run autoprefixer on that generated css to automatically insert vendor prefixes.

What I'm not sure how to do, is combine the two steps. Is it possible to chain File Watchers in Webstorm?

Possible approaches:

  • Create a batch script that is called from the file watcher, then calls less and autoprefixer in sequence.
  • Create a node.js script/module that calls less, then autoprefixer.
  • Have the less transpiler output the css with a custom extension (e.g., .unprefixedcss), then have a File Watcher specifically for that extension.
  • Something I'm missing?
like image 474
Robert K. Bell Avatar asked Mar 03 '14 07:03

Robert K. Bell


People also ask

How do I compile my code automatically in WebStorm?

To compile your code automatically, you need to configure a Sass, Less, or SCSS File Watcher which will track changes to your files and run the compiler. When you open a file, WebStorm checks whether an applicable File Watcher is available in the current project.

What is Autoprefixer CSS online?

Autoprefixer is a PostCSS plugin which parses your CSS and adds vendor prefixes Autoprefixer CSS online Autoprefixer is a PostCSS plugin which parses your CSS and adds vendor prefixes

What compilers does WebStorm integrate with?

WebStorm integrates with compilers that translate Sass, Less, and SCSS code into CSS. To use a compiler in WebStorm, you need to configure it as a File Watcher based on the relevant predefined template.

How does the file Watcher work in WebStorm?

If an applicable File Watcher is configured and enabled in the current project, WebStorm starts the compiler automatically upon the event specified in the New Watcher dialog. If the Auto-save edited files to trigger the watcher checkbox is selected, the File Watcher is invoked as soon as any changes are made to the source code.


2 Answers

There is a plugin for less which does this job without adding a watcher: https://github.com/less/less-plugin-autoprefix

After installation you can add --autoprefix="…" to your arguments for the output in webstorms file watcher.

like image 94
crtdwthlve Avatar answered Oct 10 '22 21:10

crtdwthlve


yes, it's possible to chain file watchers. The autoprefixer file watcher will listen to css changes and run after less. The first and secong approaches will work too

like image 41
lena Avatar answered Oct 10 '22 20:10

lena