Skip to content

Commit 1f08343

Browse files
author
Andrey Fedoseev
committed
Add source maps support for SASS/SCSS
1 parent 60a67b5 commit 1f08343

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changes
33
=======
44

5+
Dev
6+
===
7+
8+
- Add source maps support for SASS/SCSS
9+
10+
511
1.0.1
612
=====
713

README.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,16 @@ SASS / SCSS
203203
``executable``
204204
Path to SASS compiler executable. Default: "sass".
205205

206+
``sourcemap_enabled``
207+
Boolean. Set to ``True`` to enable source maps. Default: ``False``
208+
206209
``compass_enabled``
207210
Boolean. Whether to use compass or not. Compass must be installed in your system. Run "sass --compass" and if no error is shown it means that compass is installed.
208211

209212
Example::
210213

211214
STATIC_PRECOMPILER_COMPILERS = (
212-
('static_precompiler.compilers.SCSS', {"executable": "/usr/bin/sass", "compass_enabled": True}),
215+
('static_precompiler.compilers.SCSS', {"executable": "/usr/bin/sass", "sourcemap_enabled": True, "compass_enabled": True}),
213216
)
214217

215218

static_precompiler/compilers/scss.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ class SCSS(base.BaseCompiler):
2222

2323
IMPORT_RE = re.compile(r"@import\s+(.+?)\s*;", re.DOTALL)
2424

25-
def __init__(self, executable=settings.SCSS_EXECUTABLE, compass_enabled=settings.SCSS_USE_COMPASS):
25+
def __init__(self, executable=settings.SCSS_EXECUTABLE, sourcemap_enabled=False,
26+
compass_enabled=settings.SCSS_USE_COMPASS):
2627
self.executable = executable
28+
self.is_sourcemap_enabled = sourcemap_enabled
2729
self.is_compass_enabled = compass_enabled
2830
super(SCSS, self).__init__()
2931

@@ -38,7 +40,7 @@ def compile_file(self, source_path):
3840
full_output_path = self.get_full_output_path(source_path)
3941
args = [
4042
self.executable,
41-
"--sourcemap=none",
43+
"--sourcemap={}".format("auto" if self.is_sourcemap_enabled else "none"),
4244
]
4345

4446
if self.is_compass_enabled:

static_precompiler/tests/test_scss.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ def test_compile_file(monkeypatch, tmpdir):
2929
"""
3030

3131

32+
def test_sourcemap(monkeypatch, tmpdir):
33+
34+
monkeypatch.setattr("static_precompiler.settings.ROOT", tmpdir.strpath)
35+
monkeypatch.setattr("static_precompiler.utils.convert_urls", lambda *args: None)
36+
37+
compiler = compilers.SCSS(sourcemap_enabled=False)
38+
compiler.compile_file("styles/test.scss") == "COMPILED/styles/test.css"
39+
full_output_path = compiler.get_full_output_path("styles/test.scss")
40+
assert not os.path.exists(full_output_path + ".map")
41+
42+
compiler = compilers.SCSS(sourcemap_enabled=True)
43+
compiler.compile_file("styles/test.scss") == "COMPILED/styles/test.css"
44+
full_output_path = compiler.get_full_output_path("styles/test.scss")
45+
assert os.path.exists(full_output_path + ".map")
46+
47+
3248
def test_compile_source():
3349
compiler = compilers.SCSS(executable="scss")
3450
assert (

0 commit comments

Comments
 (0)