0
votes

I am trying to compile the bootstrap less file using less js and trying to save the compiled css file to my server root folder.

I am little bit confused about which bootstrap less files to be included out of 40 less files. Currently I am including following files to get the bootstrap css:

  1. bootstrap.less
  2. variables.less

For changing the variables values and compiling, I am doing following:

HTML:

<body>
<div class="bg-primary"style="width:100%;height:100px"></div>
    <a class="btn btn-primary" onclick="generatecss();"> compile </a>
</body>

JS:

function generatecss() {
    less.modifyVars({
        '@brand-primary': '#5cb85c'
    });
}

After executing above js function the less is compiled properly changing the brand-primary color. But my problem is that how should I save this newly compiled file to my server root directory.

1

1 Answers

2
votes

LESS is not typically compiled from the browser, but rather from the command-line with lessc. After it's installed (likely using NPM), you should be able to compile Bootstrap with something like

% lessc bootstrap/less/bootstrap.less my-bootstrap.css

Then you only need to distribute the resulting my-bootstrap.css—no need to serve the LESS sources.

If you want to modify that variable as you did with the JavaScript code, you can either edit Bootstrap's variables.less or pass another command-line option:

% lessc --modify-var='brand-primary=#5cb85c' bootstrap/less/bootstrap.less my-bootstrap.css

lessc can take other options as well—try lessc --help to view them.