Less compiler is a better way to write CSS. ActiveWeb provides a built-in mechanism to generate CSS file on the fly with a use of a Less compiler.
Less configuration below requires that you install a Less compiler from: Less compiler
Here is how to configure:
First, configure the routes to ignore "/bootstrap.css" route in all environments except development:
1 2 3 4 5
This way, your app will ignoring the
/bootstrap.css request in all environments except development. The goal is for all other environments to have your web server serve this file, which will be created during the build.
Create controller for development environment
Then, create a new controller:
1 2 3 4 5 6
And override the
getLessFile() method to return a location of your main Less file.
This controller will be called every time your browser hits
/bootstrap.cssroute, and will recompile all LESS files on the fly. This approach will allow you to rapidly work with LESS files without having to recompile manually
Maven Plugin with a Single LESS file
Use LessC maven Plugin in order to compile a static CSS file from your LESS files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Maven Plugin with Multiple LESS files
If your project has more than one LESS files, you can use alternative configuration to compile multiple files during the build:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
lesscArgumentshas an issue with quotes. Seems that the double quots are not needed.
Package the CSS into War file
Configure to package the CSS file into the app with a War plugin:
1 2 3 4 5 6 7 8 9 10 11 12
As a result, when your application is running in development environment, the
BootstrapController is compiling CSS from less files in cases there are changes in the files. It checks for changes and re-compiles if needed on each request. During the build, the plugin fully compiles all Less files into a single target CSS file, which then gets packaged into the war file. The file
bootstrap.css is then served from container, because this path is ignored in any environment except development. In fact, in a real production system this file like any other static files will be served by a web server or a CDN.
How to comment
The comment section below is to discuss documentation on this page.
If you have an issue, or discover bug, please follow instructions on the Support page