forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsass.bzl
More file actions
80 lines (66 loc) · 2.26 KB
/
sass.bzl
File metadata and controls
80 lines (66 loc) · 2.26 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"Sass compilation rules"
load("@npm//client/build-config:sass/package_json.bzl", sass_bin = "bin")
load("@npm//client/build-config:postcss-cli/package_json.bzl", postcss_bin = "bin")
# A filename for the intermediate file between sass + postcss
def _sass_out(n):
return n.replace(".scss", "_scss.css")
# SASS and PostCSS
def sass(name, srcs, deps = [], runtime_deps = [], **kwargs):
"""Runs SASS and PostCSS on sass inputs
Args:
name: A unique name for the terminal target
srcs: A list of .scss sources
deps: A list of dependencies
runtime_deps: A list of runtime_dependencies
**kwargs: Additional arguments
"""
visibility = kwargs.pop("visibility", None)
sass_bin.sass(
name = "_%s_sass" % name,
srcs = srcs + deps,
outs = [_sass_out(src) for src in srcs] + ["%s.map" % _sass_out(src) for src in srcs],
args = [
"--load-path=client",
"--load-path=node_modules",
] + [
"$(execpath {}):{}/{}".format(src, native.package_name(), _sass_out(src))
for src in srcs
],
visibility = ["//visibility:private"],
)
for src in srcs:
_postcss(
name = src.replace(".scss", "_css"),
src = _sass_out(src),
out = src.replace(".scss", ".css"),
# Same visibility as filegroup of outputs
visibility = visibility,
)
native.filegroup(
name = name,
srcs = [src.replace(".scss", ".css") for src in srcs] + [src.replace(".scss", ".css.map") for src in srcs],
visibility = visibility,
data = runtime_deps,
# Allow any other args
**kwargs
)
def _postcss(name, src, out, **kwargs):
postcss_bin.postcss(
name = name,
srcs = [
src,
"%s.map" % src,
"//:postcss_config_js",
],
outs = [out, out + ".map"],
# rules_js runs in the execroot under the output tree in bazel-out/[arch]/bin
args = [
"../../../$(execpath %s)" % src,
"--config",
"../../../$(execpath //:postcss_config_js)",
"--map",
"--output",
"../../../$(@D)/%s" % out,
],
**kwargs
)