Best way to auto compile compass-style SASS via maven

末鹿安然 提交于 2019-12-03 07:01:58
seanf

I suppose you know about this Maven plugin (mentioned in SASS implementation for Java?)? : https://github.com/Jasig/sass-maven-plugin

(I haven't tried it myself yet.)

UPDATE: that plugin is no longer supported. However, this fork seems to be healthy at present, so it might be an option for some: https://github.com/GeoDienstenCentrum/sass-maven-plugin

I found this, it's not a special compass/sass plugin but it works

https://gist.github.com/1671207

BlondCode

I tried several ways to compile my app (java, Wicket, using Zurb Foundation Sites, node-sass with depebndency of lib-sass). To tell you the truth, all the maven plugins were somewhere a deadend, especially when my scss contained the !global flag. (This flag came with foundations.) So the final solution for us was to build with npm first then use maven. Npm builds into src/main/webapp/"myDir" dir. I excluded this dir in git. The jason file has a line like:

"scripts": {
    ....
    "build-css": "node node_modules/node-sass/bin/node-sass --include-path myScssDir myScssDir/myScss.scss --output  src/main/webapp/myDir/css",
    ....
}

Then build with maven and it will move the builded css ino my war. For some help (create the nonexisting "myDir" dir) i used mkdirp. In my jason there is:

"scripts": {
    "create-dirs": "mkdirp src/main/webapp/myDir/",
    ....
}

So i run "npm i" to install all my dependencies locally into node-modules dir. This is gitignored.

Then i run "npm run create-dirs" to create the necessary myDir. This is gitignored as well.

Then i run "npm run build-css" to compile my css-s and js-s into myDir.

Finally i make a maven build.

With a hudson/jenkins build, you can easily do these in one job.

One improvement i can think of is to run npm via ant during maven build. I'll get back to you when i have a proof of concept of this.

//One extra hint: if you are developing under corporate environment and Windows7 you may have to add permissions to symbolic links for npm build. If you find errors in npm build, it worth a try: https://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7

I was using the Sass Maven Plugin by nl.geodienstencentrum.maven but it uses Ruby and is very slow.

I've now switched to: Libsass Maven Plugin

https://github.com/warmuuh/libsass-maven-plugin

This uses C and our compile times are much less (8.6 seconds to -> 2 seconds)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!