-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
939 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright 2020 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "codeowners", "pkg_npm") | ||
load("@build_bazel_rules_nodejs//tools/stardoc:index.bzl", "stardoc") | ||
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
codeowners( | ||
teams = ["@mattem"], | ||
) | ||
|
||
bzl_library( | ||
name = "bzl", | ||
srcs = glob(["**/*.bzl"]), | ||
deps = [ | ||
"@bazel_skylib//lib:paths", | ||
"@build_bazel_rules_nodejs//:bzl", | ||
"@build_bazel_rules_nodejs//internal/common:bzl", | ||
"@build_bazel_rules_nodejs//internal/node:bzl", | ||
], | ||
) | ||
|
||
stardoc( | ||
name = "docs", | ||
testonly = True, | ||
out = "index.md", | ||
input = "index.bzl", | ||
tags = ["fix-windows"], | ||
deps = [":bzl"], | ||
) | ||
|
||
genrule( | ||
name = "generate_README", | ||
srcs = [ | ||
"_README.md", | ||
"index.md", | ||
], | ||
outs = ["README.md"], | ||
cmd = """cat $(execpath _README.md) $(execpath index.md) | sed 's/^##/\\\n##/' > $@""", | ||
tags = ["fix-windows"], | ||
visibility = ["//docs:__pkg__"], | ||
) | ||
|
||
copy_file( | ||
name = "npm_version_check", | ||
src = "//internal:npm_version_check.js", | ||
out = ":npm_version_check.js", | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_package", | ||
srcs = [ | ||
"esbuild.bzl", | ||
"esbuild_repo.bzl", | ||
"helpers.bzl", | ||
"index.bzl", | ||
"package.json", | ||
], | ||
build_file_content = " ", | ||
deps = [ | ||
":npm_version_check", | ||
] + select({ | ||
# FIXME: fix stardoc on Windows; //packages/karma:index.md generation fails with: | ||
# ERROR: D:/b/62unjjin/external/npm_bazel_karma/BUILD.bazel:65:1: Couldn't build file | ||
# external/npm_bazel_karma/docs.raw: Generating proto for Starlark doc for docs failed (Exit 1) | ||
"@bazel_tools//src/conditions:windows": [], | ||
"//conditions:default": [":generate_README"], | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# esbuild rules for Bazel | ||
|
||
The esbuild rules runs the [esbuild](https://github.com/evanw/esbuild) bundler tool with Bazel. | ||
|
||
## Installation | ||
|
||
Add the `@bazel/esbuild` npm packages to your `devDependencies` in `package.json`. | ||
|
||
``` | ||
npm install --save-dev @bazel/esbuild | ||
``` | ||
or using yarn | ||
``` | ||
yarn add -D @bazel/esbuild | ||
``` | ||
|
||
Add the esbuild repository to the `WORKSPACE` file | ||
|
||
```python | ||
load("@npm//@bazel/esbuild:index.bzl", "esbuild_repository") | ||
|
||
esbuild_repository(name = "esbuild") | ||
``` | ||
|
||
The version of `esbuild` can be specified by passing the `version` and `platform_sha` attributes | ||
|
||
```python | ||
load("@npm//@bazel/esbuild:index.bzl", "esbuild_repository") | ||
|
||
esbuild_repository( | ||
name = "esbuild", | ||
version = "0.7.19", | ||
platform_sha = { | ||
"darwin_64": "deadf43c0868430983234f90781e1b542975a2bc3549b2353303fac236816149", | ||
"linux_64": "2d25ad82dba8f565e8766b838acd3b966f9a2417499105ec10afb01611594ef1", | ||
"windows_64": "135b2ff549d4b1cfa4f8e2226f85ee97641b468aaced7585112ebe8c0af2d766", | ||
} | ||
) | ||
``` | ||
|
||
## Example use of esbuild | ||
|
||
The `esbuild` rule can take a JS or TS dependency tree and bundle it to a single file, or split across multiple files, outputting a directory. | ||
|
||
```python | ||
ts_library( | ||
name = "lib", | ||
srcs = ["a.ts"], | ||
) | ||
|
||
esbuild( | ||
name = "bundle", | ||
entry_point = "a.ts", | ||
deps = [":lib"], | ||
) | ||
``` | ||
|
||
The above will create three output files, `bundle.js`, `bundle.js.map` and `bundle_metadata.json` which contains the bundle metadata to aid in debugging and resoloution tracing. | ||
|
||
Further options for minifying and splitting are available. |
Oops, something went wrong.