Skip to content

Commit 4c20f32

Browse files
theRustyKnifeAndrey Fedoseev
authored andcommitted
Add clean css option to less (#118)
Add clean css option to less
1 parent bf16a66 commit 4c20f32

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

docs/compiler-settings.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ LESS
206206
``include_path``
207207
List of additional directories to look for imported files (``--include-path`` command line option). Default: ``None``.
208208

209+
``clean_css``
210+
Boolean. Set to ``True`` to use the `clean-css <https://github.com/less/less-plugin-clean-css>`_ plugin to minify the output. Default ``False``.
211+
209212
``global_vars``
210213
Dictionary of global variables (``--global-var`` command line option). Default: ``None``.
211214

static_precompiler/compilers/less.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ class LESS(base.BaseCompiler):
2020
IMPORT_RE = re.compile(r"@import\s+(.+?)\s*;", re.DOTALL)
2121
IMPORT_ITEM_RE = re.compile(r"([\"'])(.+?)\1")
2222

23-
def __init__(self, executable="lessc", sourcemap_enabled=False, include_path=None, global_vars=None):
23+
def __init__(self, executable="lessc", sourcemap_enabled=False, include_path=None, clean_css=False,
24+
global_vars=None):
2425
self.executable = executable
2526
self.is_sourcemap_enabled = sourcemap_enabled
2627
if isinstance(include_path, (list, tuple)):
2728
include_path = ';'.join(include_path)
2829
self.include_path = include_path
30+
self.clean_css = clean_css
2931
self.global_vars = global_vars
3032
super(LESS, self).__init__()
3133

@@ -54,6 +56,10 @@ def compile_file(self, source_path):
5456
args.extend([
5557
"--include-path={}".format(self.include_path)
5658
])
59+
if self.clean_css:
60+
args.extend([
61+
"--clean-css",
62+
])
5763
if self.global_vars:
5864
for variable_name, variable_value in self.global_vars.items():
5965
args.extend([

0 commit comments

Comments
 (0)