Skip to content

Commit faeb874

Browse files
committed
build: properly publish sass files in release packages
Currently with Gulp we have a **hacky** script that fixes up relative imports in sass files. This is something we cannot easily do with Bazel when we assemble the release package. Primarily because of that limitation/complexity with Bazel and the general preference to avoid such hacky rewrites, we now ship all individual "scss_lib" files to the release output. This way all relative style references remain *correct* when the release packages are assembled. This means that we no longer need a hacky script to rewrite the imports. For backwards compatibility, the `_theming.scss` entry-point at the root of the Material package is still created. It just isn't a sass bundle anymore, but the functionality remains the same (making it a bundle means we repeat a *lot* of code; also there no real big benefit as we don't have too deep dependencies) Same has been done for the CDK sass files (overlay, a11y, text-field), where we still expose the prebuilt css and sass files at the top-level of the release output. In the future, we can consider removing these backwards-compatibility changes in favor of a less convoluted bazel setup.
1 parent 2bfaa05 commit faeb874

File tree

12 files changed

+36
-54
lines changed

12 files changed

+36
-54
lines changed

packages.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ CDK_TARGETS_WITH_STYLES = [
3333
"text-field",
3434
]
3535

36+
CDK_SCSS_LIBS = [
37+
"//src/cdk/%s:%s_scss_lib" % (p, p.replace("-", "_"))
38+
for p in CDK_TARGETS_WITH_STYLES
39+
]
40+
3641
CDK_TARGETS = ["//src/cdk"] + ["//src/cdk/%s" % p for p in CDK_PACKAGES]
3742

3843
CDK_EXPERIMENTAL_PACKAGES = [

src/cdk/BUILD.bazel

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//:packages.bzl", "CDK_PACKAGES", "CDK_TARGETS", "CDK_TARGETS_WITH_STYLES", "ROLLUP_GLOBALS")
3+
load("//:packages.bzl", "CDK_PACKAGES", "CDK_SCSS_LIBS", "CDK_TARGETS", "CDK_TARGETS_WITH_STYLES", "ROLLUP_GLOBALS")
44
load("//tools:defaults.bzl", "ng_module", "ng_package")
55

66
# Root "@angular/cdk" entry-point that does not re-export individual entry-points.
@@ -56,10 +56,7 @@ rerootedStyleTargets = ["%s_rerooted" % file for [
5656
ng_package(
5757
name = "npm_package",
5858
srcs = ["package.json"],
59-
data = ["%s_rerooted" % file for [
60-
file,
61-
_,
62-
] in rerootedStyles],
59+
data = rerootedStyleTargets + CDK_SCSS_LIBS,
6360
entry_point = ":public-api.ts",
6461
globals = ROLLUP_GLOBALS,
6562
packages = [

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ sass_binary(
8888
"//src/material-experimental/mdc-theming:all_themes",
8989
"//src/material-experimental/mdc-typography:all_typography",
9090
"//src/material-experimental/popover-edit:popover_edit_scss_lib",
91-
"//src/material/core:all_themes",
91+
"//src/material/core:theming_scss_lib",
9292
],
9393
)
9494

src/e2e-app/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ sass_binary(
8181
"//src/material-experimental/mdc-radio:mdc_radio_scss_lib",
8282
"//src/material-experimental/mdc-slide-toggle:mdc_slide_toggle_scss_lib",
8383
"//src/material-experimental/mdc-tabs:mdc_tabs_scss_lib",
84-
"//src/material/core:all_themes",
84+
"//src/material/core:theming_scss_lib",
8585
],
8686
)
8787

src/material-experimental/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//:packages.bzl", "MATERIAL_EXPERIMENTAL_TARGETS", "ROLLUP_GLOBALS")
3+
load("//:packages.bzl", "MATERIAL_EXPERIMENTAL_SCSS_LIBS", "MATERIAL_EXPERIMENTAL_TARGETS", "ROLLUP_GLOBALS")
44
load("//tools:defaults.bzl", "ng_module", "ng_package")
55

66
exports_files(["mdc_require_config.js"])
@@ -20,6 +20,7 @@ ng_module(
2020
ng_package(
2121
name = "npm_package",
2222
srcs = ["package.json"],
23+
data = MATERIAL_EXPERIMENTAL_SCSS_LIBS,
2324
entry_point = ":public-api.ts",
2425
globals = ROLLUP_GLOBALS,
2526
tags = ["release-package"],

src/material-experimental/mdc-autocomplete/BUILD.bazel

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ sass_library(
2626
srcs = glob(["**/_*.scss"]),
2727
deps = [
2828
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
29-
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
30-
"//src/material/core:core_scss_lib",
3129
],
3230
)
3331

@@ -37,11 +35,7 @@ sass_binary(
3735
include_paths = [
3836
"external/npm/node_modules",
3937
],
40-
deps = [
41-
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
42-
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
43-
"//src/material/core:all_themes",
44-
],
38+
deps = [],
4539
)
4640

4741
ng_e2e_test_library(

src/material-experimental/mdc-select/BUILD.bazel

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ sass_library(
3838
srcs = glob(["**/_*.scss"]),
3939
deps = [
4040
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
41-
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
42-
"//src/material/core:core_scss_lib",
4341
],
4442
)
4543

@@ -49,11 +47,7 @@ sass_binary(
4947
include_paths = [
5048
"external/npm/node_modules",
5149
],
52-
deps = [
53-
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
54-
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
55-
"//src/material/core:all_themes",
56-
],
50+
deps = [],
5751
)
5852

5953
ng_test_library(

src/material/BUILD.bazel

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,12 @@ load(
88
"ROLLUP_GLOBALS",
99
)
1010
load("//tools:defaults.bzl", "ng_package", "ts_library")
11-
load("//tools:sass_bundle.bzl", "sass_bundle")
1211

1312
ts_library(
1413
name = "material",
1514
srcs = ["index.ts"],
1615
)
1716

18-
sass_bundle(
19-
name = "theming_bundle",
20-
srcs = [
21-
"//src/cdk/a11y:a11y_scss_lib",
22-
"//src/cdk/overlay:overlay_scss_lib",
23-
"//src/cdk/text-field:text_field_scss_lib",
24-
] + MATERIAL_SCSS_LIBS,
25-
entry_point = "//src/material/core:theming/_all-theme.scss",
26-
output_name = "_theming.scss",
27-
)
28-
2917
filegroup(
3018
name = "overviews",
3119
srcs = ["//src/material/%s:overview" % name for name in MATERIAL_PACKAGES],
@@ -34,14 +22,17 @@ filegroup(
3422
# Creates the @angular/material package published to npm.
3523
ng_package(
3624
name = "npm_package",
37-
srcs = ["package.json"],
25+
srcs = [
26+
"_theming.scss",
27+
"package.json",
28+
],
3829
data = [
39-
":theming_bundle",
30+
"//src/material/core:theming_scss_lib",
4031
"//src/material/prebuilt-themes:deeppurple-amber",
4132
"//src/material/prebuilt-themes:indigo-pink",
4233
"//src/material/prebuilt-themes:pink-bluegrey",
4334
"//src/material/prebuilt-themes:purple-green",
44-
],
35+
] + MATERIAL_SCSS_LIBS,
4536
entry_point = ":index.ts",
4637
entry_point_name = "material",
4738
globals = ROLLUP_GLOBALS,

src/material/_theming.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Replicate the old "theming" bundle by just importing the entry-point
2+
// that was used to construct the theming bundle.
3+
@import './core/theming/_all-theme';

src/material/core/BUILD.bazel

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ sass_library(
5353
],
5454
)
5555

56+
sass_library(
57+
name = "theming_scss_lib",
58+
srcs = [
59+
"theming/_all-theme.scss",
60+
],
61+
deps = MATERIAL_SCSS_LIBS,
62+
)
63+
5664
sass_binary(
5765
name = "pseudo_checkbox_scss",
5866
src = "selection/pseudo-checkbox/pseudo-checkbox.scss",
@@ -71,37 +79,28 @@ sass_binary(
7179
deps = [":core_scss_lib"],
7280
)
7381

74-
sass_library(
75-
name = "all_themes",
76-
srcs = [
77-
"theming/_all-theme.scss",
78-
"typography/_all-typography.scss",
79-
],
80-
deps = MATERIAL_SCSS_LIBS,
81-
)
82-
8382
sass_binary(
8483
name = "indigo_pink_prebuilt",
8584
src = "theming/prebuilt/indigo-pink.scss",
86-
deps = [":all_themes"],
85+
deps = [":theming_scss_lib"],
8786
)
8887

8988
sass_binary(
9089
name = "deeppurple-amber_prebuilt",
9190
src = "theming/prebuilt/deeppurple-amber.scss",
92-
deps = [":all_themes"],
91+
deps = [":theming_scss_lib"],
9392
)
9493

9594
sass_binary(
9695
name = "pink-bluegrey_prebuilt",
9796
src = "theming/prebuilt/pink-bluegrey.scss",
98-
deps = [":all_themes"],
97+
deps = [":theming_scss_lib"],
9998
)
10099

101100
sass_binary(
102101
name = "purple-green_prebuilt",
103102
src = "theming/prebuilt/purple-green.scss",
104-
deps = [":all_themes"],
103+
deps = [":theming_scss_lib"],
105104
)
106105

107106
#################
@@ -144,5 +143,5 @@ sass_binary(
144143
name = "test-css-variables-theme",
145144
testonly = True,
146145
src = "theming/test-css-variables-theme.scss",
147-
deps = [":all_themes"],
146+
deps = [":theming_scss_lib"],
148147
)

src/material/core/_core.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// We can use relative imports for imports from the cdk because we bundle everything
2-
// up into a single flat scss file for material.
31
@import '../../cdk/overlay/overlay';
42
@import '../../cdk/a11y/a11y';
53
@import '../../cdk/text-field/text-field';

src/universal-app/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sass_binary(
4545
deps = [
4646
"//src/material-experimental/mdc-theming:all_themes",
4747
"//src/material-experimental/mdc-typography:all_typography",
48-
"//src/material/core:all_themes",
48+
"//src/material/core:theming_scss_lib",
4949
],
5050
)
5151

0 commit comments

Comments
 (0)