-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): show the create-react-app converted to bazel build
- Loading branch information
Showing
6 changed files
with
111 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
load("@npm//react-scripts:index.bzl", "react_scripts") | ||
|
||
# We don't want to teach react-scripts to include from multiple directories | ||
# So we copy everything it wants to read to the output "bin" directory | ||
copy_to_bin( | ||
name = "copy_static_files", | ||
srcs = glob([ | ||
"public/*", | ||
"src/*", | ||
]) + [ | ||
"package.json", | ||
"tsconfig.json", | ||
], | ||
) | ||
|
||
# react-scripts can only work if the working directory is the root of the application. | ||
# So we'll need to chdir before it runs. | ||
write_file( | ||
name = "write_chdir_script", | ||
out = "chdir.js", | ||
content = ["process.chdir(__dirname)"], | ||
) | ||
|
||
react_scripts( | ||
# Note: this must be named "build" since react-scripts hard-codes that as the output dir | ||
name = "build", | ||
args = [ | ||
"--node_options=--require=./$(execpath chdir.js)", | ||
"build", | ||
], | ||
data = [ | ||
"chdir.js", | ||
"copy_static_files", | ||
"@npm//@types", | ||
"@npm//react", | ||
"@npm//react-dom", | ||
], | ||
output_dir = True, | ||
) |
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,30 @@ | ||
workspace( | ||
name = "create_react_app", | ||
managed_directories = {"@npm": ["node_modules"]}, | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "build_bazel_rules_nodejs", | ||
sha256 = "cb6d92c93a1769205d6573c21363bdbdcf5831af114a7fbc3f800b8598207dee", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/2.0.0-rc.2/rules_nodejs-2.0.0-rc.2.tar.gz"], | ||
) | ||
|
||
http_archive( | ||
name = "bazel_skylib", | ||
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", | ||
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", | ||
], | ||
) | ||
|
||
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install") | ||
|
||
yarn_install( | ||
# Name this npm so that Bazel Label references look like @npm//package | ||
name = "npm", | ||
package_json = "//:package.json", | ||
yarn_lock = "//:yarn.lock", | ||
) |
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