blob: a658475ebcc4f4fd76952292e66f51b6e53d40a3 [file] [log] [blame]
load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle")
load("@io_bazel_rules_sass//:defs.bzl", "sass_library")
load("//infra-sk/remove_css_imports_from_js:index.bzl", "remove_css_imports_from_js")
package(default_visibility=["//visibility:public"])
exports_files(["rollup.config.js"])
#################################
# Sass library for elements-sk. #
#################################
sass_library(
name = "elements-sk_scss",
srcs = glob(["node_modules/elements-sk/**/*.scss"]) + ["//:~elements-sk"],
)
# The UMD bundles below are only necessary for karma_mocha_test and karma_web_test BUILD targets,
# which require 3rd-party dependencies to be bundled as UMD modules and provided explicitly via the
# srcs argument.
##############################
# UMD bundles for common-sk. #
##############################
COMMON_SK_MODULES = [
filename # node_modules/common-sk/modules/dom.js
.replace("node_modules/common-sk/modules/", "") # dom.js
.replace(".js", "") # dom
for filename in glob(["node_modules/common-sk/modules/*.js"])
if not filename.endswith("_test.js")
]
[
npm_umd_bundle(
name = "common-sk_%s_umd" % module,
package_name = "common-sk/modules/%s" % module,
entry_point = "@infra-sk_npm//:node_modules/common-sk/modules/%s.js" % module,
package = "@infra-sk_npm//common-sk",
)
for module in COMMON_SK_MODULES
]
filegroup(
name = "common-sk_umd",
srcs = ["common-sk/modules/%s.umd.js" % module for module in COMMON_SK_MODULES],
)
################################
# UMD bundles for elements-sk. #
################################
ELEMENTS_SK_MODULES = [
filename # node_modules/elements-sk/icon/add-icon-sk.js
.replace("node_modules/elements-sk/", "") # icon/add-icon-sk.js
.replace(".js", "") # icon/add-icon-sk
for filename in glob(["node_modules/elements-sk/**/*.js"])
if not filename.endswith("_test.js")
]
[
npm_umd_bundle(
name = "elements-sk_%s_umd" % module.replace("/", "__"),
package_name = "elements-sk/%s" % module,
entry_point = "@infra-sk_npm//:node_modules/elements-sk/%s.js" % module,
package = "@infra-sk_npm//elements-sk",
excluded = [
# The npm_umd_bundle rule fails with e.g. "Error: Cannot find module './buttons.scss'"
# when it encounters Sass/CSS modules imported from JavaScript code, e.g.
# "import './buttons.css'", because it treats all imports as JavaScript imports.
# Excluding any imported Sass/CSS modules prevents said erros.
"./buttons.scss",
"./checkbox-sk.scss",
"./collapse-sk.scss",
"./icon-sk.scss",
"./multi-select-sk.scss",
"./nav-links-sk.scss",
"./radio-sk.scss",
"./select.scss",
"./select-sk.scss",
"./spinner-sk.scss",
"./table.scss",
"./tabs-panel-sk.scss",
"./tabs-sk.scss",
"./toast-sk.scss",
],
)
for module in ELEMENTS_SK_MODULES
]
# Some elements-sk modules import CSS files from JavaScript, e.g. `import "styles.css"`. When said
# elements-sk modules are bundled as UMD modules and loaded from a Karma test, the test fails
# because the `require("styles.css")` imports in the UMD modules cannot be resolved.
#
# Erasing the CSS imports from the UMD bundles prevents these errors. This is OK because the CSS
# imports are only intended for generating CSS bundles with Webpack and the css-loader plugin, and
# have no effect when Webpack is not used.
[
remove_css_imports_from_js(
name = "elements-sk_%s_umd_nocss" % module.replace("/", "__"),
src = ":elements-sk/%s.umd.js" % module,
out = ":elements-sk/%s.umd.nocss.js" % module,
)
for module in ELEMENTS_SK_MODULES
]
filegroup(
name = "elements-sk_umd",
srcs = ["elements-sk/%s.umd.nocss.js" % module for module in ELEMENTS_SK_MODULES],
)
######################
# Other UMD bundles. #
######################
npm_umd_bundle(
name = "lit-html_umd",
package_name = "lit-html",
entry_point = "@infra-sk_npm//:node_modules/lit-html/lit-html.js",
package = "@infra-sk_npm//lit-html",
)
npm_umd_bundle(
name = "chai_umd",
package_name = "chai",
entry_point = "@infra-sk_npm//:node_modules/chai/lib/chai.js",
package = "@infra-sk_npm//chai",
)
npm_umd_bundle(
name = "sinon_umd",
package_name = "sinon",
entry_point = "@infra-sk_npm//:node_modules/sinon/lib/sinon.js",
package = "@infra-sk_npm//sinon",
)
npm_umd_bundle(
name = "fetch-mock_umd",
package_name = "fetch-mock",
entry_point = "@infra-sk_npm//:node_modules/fetch-mock/esm/client.js",
package = "@infra-sk_npm//fetch-mock",
)