Web developer. Backend + Frontend. Learning about designing user interfaces, improvement of user experience and its implementation.
Compiling Sass with Maven or Gulp
by JMTALARN Oct 21, 2015
Sass compiling from Maven
You can compile your sass css source files from your java projects build with maven with the sass-maven-plugin.
You can find the source code at GitHub https://github.com/Jasig/sass-maven-plugin, and find it on the Maven Central Repository.
You should configure your maven pom file to properly use the plugin as needed.
Add the plugin configuration in the <plugins> section of your pom.xml.
Maybe you want to prevent your .scss files to be copied in the final package compilation. Then you should add this kind of files in the exclude section inside the resources:
Also if you need to edit and replace some of the content of the results you can use the Maven replacer plugin.
Then you need to configure it:
You don’t need to install Sass separately because the Maven dependencies manager install all the requirements needed to do the compilation.
Sass compiling from Gulp
In the same way if you are using Gulp to build an prepare your project you can compile your Sass files too.
In order to do this you need to use the gulp-sass https://www.npmjs.com/package/gulp-sass plugin in your Node.js project.
Installing Node.js is one of the requirements since you are using Gulp and you should think that gulp-sass like a wrapper of the required node module node-sass which uses internally the libsass library. The Node.js package system will install the requirements needed.
The module to add in the package.json file is gulp-sass and you can add to it with this line in the command-line from your project folder:
Then you should configure a Gulp task to process your Sass files and compile them. This is an example about how to do it:
And execute it with:
For sure you can complicate it as you want, concatenating the execution of the plugins and modules you need: