On the fly LESS compiler for java web app?

后端 未结 3 779
暗喜
暗喜 2021-02-02 15:57

I am looking for a way to compile CSS LESS files on the server side on demand during development. For example if the browser makes a request to /assets/css/foo.css I want the se

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-02 16:22

    It would be simpler (and more effective) to first compile your less files to css files, during the build of your webapp.
    As an example, when using Maven, we use the lesscss-maven-plugin (compile goal, process-sources phase) to generate css files from less files. Then only the css files are used and packaged in the webapp. No less files are used dynamically.
    Another advantage is that less files are compiled before the webapp is deployed, so compilation errors are detected sooner.

    Configuration example in pom.xml :

    
        org.lesscss
        lesscss-maven-plugin
        1.3.0
        
            ${project.basedir}/src/main/webapp/less
            ${project.build.directory}/${project.build.finalName}/css
            true
            
                main.less
            
        
        
            
                
                    compile
                
            
        
    
    

提交回复
热议问题