Skip to content

Commit 262316d

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 f93a0aa commit 262316d

File tree

12 files changed

+34
-56
lines changed

12 files changed

+34
-56
lines changed

packages.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ CDK_TARGETS_WITH_STYLES = [
3030
"text-field",
3131
]
3232

33+
CDK_SCSS_LIBS = [
34+
"//src/cdk/%s:%s_scss_lib" % (p, p.replace("-", "_"))
35+
for p in CDK_TARGETS_WITH_STYLES
36+
]
37+
3338
CDK_TARGETS = ["//src/cdk"] + ["//src/cdk/%s" % p for p in CDK_PACKAGES]
3439

3540
CDK_EXPERIMENTAL_PACKAGES = [

src/cdk/BUILD.bazel

Lines changed: 9 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.
@@ -35,6 +35,8 @@ rerootedStyles = [file for target in CDK_TARGETS_WITH_STYLES for file in [
3535

3636
# Copy all stylesheets to the CDK root package. We need to copy these files, as
3737
# these stylesheets need to be at the root of the NPM package (e.g. "_a11y.scss")
38+
# TODO(devversion): figure out if we can remove these rerooted styles. They are
39+
# just rerooted to keep the Bazel output backwards compatible with the gulp setup.
3840
[genrule(
3941
name = "%s_rerooted" % file,
4042
srcs = ["//src/cdk/%s:%s" % (target, file)],
@@ -45,6 +47,11 @@ rerootedStyles = [file for target in CDK_TARGETS_WITH_STYLES for file in [
4547
target,
4648
] in rerootedStyles]
4749

50+
rerootedStyleTargets = ["%s_rerooted" % file for [
51+
file,
52+
_,
53+
] in rerootedStyles]
54+
4855
filegroup(
4956
name = "overviews",
5057
srcs = ["//src/cdk/%s:overview" % name for name in CDK_PACKAGES],
@@ -54,10 +61,7 @@ filegroup(
5461
ng_package(
5562
name = "npm_package",
5663
srcs = ["package.json"],
57-
data = ["%s_rerooted" % file for [
58-
file,
59-
_,
60-
] in rerootedStyles],
64+
data = rerootedStyleTargets + CDK_SCSS_LIBS,
6165
entry_point = ":public-api.ts",
6266
globals = ROLLUP_GLOBALS,
6367
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:core_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:core_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
@@ -39,8 +39,6 @@ sass_library(
3939
srcs = glob(["**/_*.scss"]),
4040
deps = [
4141
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
42-
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
43-
"//src/material/core:core_scss_lib",
4442
],
4543
)
4644

@@ -50,11 +48,7 @@ sass_binary(
5048
include_paths = [
5149
"external/npm/node_modules",
5250
],
53-
deps = [
54-
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
55-
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
56-
"//src/material/core:all_themes",
57-
],
51+
deps = [],
5852
)
5953

6054
ng_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: 5 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,16 @@ 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",
4030
"//src/material/prebuilt-themes:deeppurple-amber",
4131
"//src/material/prebuilt-themes:indigo-pink",
4232
"//src/material/prebuilt-themes:pink-bluegrey",
4333
"//src/material/prebuilt-themes:purple-green",
44-
],
34+
] + MATERIAL_SCSS_LIBS,
4535
entry_point = ":index.ts",
4636
entry_point_name = "material",
4737
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: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//:packages.bzl", "MATERIAL_SCSS_LIBS")
54
load(
65
"//tools:defaults.bzl",
76
"markdown_to_html",
@@ -44,7 +43,6 @@ sass_library(
4443
name = "core_scss_lib",
4544
srcs = glob(
4645
["**/_*.scss"],
47-
exclude = ["theming/_all-theme.scss"],
4846
),
4947
deps = [
5048
"//src/cdk/a11y:a11y_scss_lib",
@@ -71,37 +69,28 @@ sass_binary(
7169
deps = [":core_scss_lib"],
7270
)
7371

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-
8372
sass_binary(
8473
name = "indigo_pink_prebuilt",
8574
src = "theming/prebuilt/indigo-pink.scss",
86-
deps = [":all_themes"],
75+
deps = [":core_scss_lib"],
8776
)
8877

8978
sass_binary(
9079
name = "deeppurple-amber_prebuilt",
9180
src = "theming/prebuilt/deeppurple-amber.scss",
92-
deps = [":all_themes"],
81+
deps = [":core_scss_lib"],
9382
)
9483

9584
sass_binary(
9685
name = "pink-bluegrey_prebuilt",
9786
src = "theming/prebuilt/pink-bluegrey.scss",
98-
deps = [":all_themes"],
87+
deps = [":core_scss_lib"],
9988
)
10089

10190
sass_binary(
10291
name = "purple-green_prebuilt",
10392
src = "theming/prebuilt/purple-green.scss",
104-
deps = [":all_themes"],
93+
deps = [":core_scss_lib"],
10594
)
10695

10796
#################
@@ -144,5 +133,5 @@ sass_binary(
144133
name = "test-css-variables-theme",
145134
testonly = True,
146135
src = "theming/test-css-variables-theme.scss",
147-
deps = [":all_themes"],
136+
deps = [":core_scss_lib"],
148137
)

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
@@ -44,7 +44,7 @@ sass_binary(
4444
deps = [
4545
"//src/material-experimental/mdc-theming:all_themes",
4646
"//src/material-experimental/mdc-typography:all_typography",
47-
"//src/material/core:all_themes",
47+
"//src/material/core:core_scss_lib",
4848
],
4949
)
5050

0 commit comments

Comments
 (0)