Skip to content

Commit 3e2d434

Browse files
committed
Add JS Serve example
1 parent 2ff1b57 commit 3e2d434

File tree

10 files changed

+47
-1794
lines changed

10 files changed

+47
-1794
lines changed

devserver/defs.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def devserver(name, port, static_files, workspace_name, debug = False, data = []
3737
deps = ["@bazel_tools//tools/cpp/runfiles"],
3838
linkopts = ["-lpthread"],
3939
copts = ["-fpermissive", "-w"],
40-
includes = ["@rules_devserver//devserver"],
40+
includes = ["@rules_devserver//devserver", "."],
4141
)

devserver/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using FileContents = std::string;
2424

2525
using PathMap = std::map<Path, FileContents>;
2626

27-
bool DEBUG = true;
27+
bool DEBUG = false;
2828

2929
#define DEBUG_LOG(msg) \
3030
if (DEBUG) std::cout << msg << std::endl;

examples/WORKSPACE

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1 @@
11
workspace(name = "devserver_examples")
2-
3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4-
http_archive(
5-
name = "build_bazel_rules_nodejs",
6-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.0/rules_nodejs-5.8.0.tar.gz"],
7-
)
8-
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
9-
build_bazel_rules_nodejs_dependencies()
10-
11-
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
12-
node_repositories(
13-
node_version = "18.12.1",
14-
)
15-
npm_install(
16-
name = "npm",
17-
package_json = "//ts_serve:package.json",
18-
package_lock_json = "//ts_serve:package-lock.json",
19-
)

examples/js_serve/BUILD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
load("//devserver:defs.bzl", "devserver")
2+
3+
filegroup(
4+
name = "hello_world",
5+
srcs = ["hello_world.js"],
6+
visibility = ["//visibility:public"],
7+
)
8+
9+
filegroup(
10+
name = "index",
11+
srcs = ["index.html"],
12+
visibility = ["//visibility:public"],
13+
)
14+
15+
devserver(
16+
name = "serve",
17+
port = 8081,
18+
workspace_name = "rules_devserver",
19+
static_files = {
20+
"/": [":index", "index.html"],
21+
"/js/hello_world.js": [":hello_world", "hello_world.js"]
22+
},
23+
debug = True,
24+
data = [":index", ":hello_world"]
25+
)

examples/js_serve/hello_world.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function add(a, b) {
2+
return a + b;
3+
}
4+
5+
const container = document.getElementById('container');
6+
if (container) {
7+
container.innerHTML = 'Served addition from JS: 1 + 2 = ' + add(1, 2);
8+
}

examples/js_serve/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
3+
<head>
4+
<title>JavaScript Serve Example</title>
5+
<script defer src="/js/hello_world.js"></script>
6+
</head>
7+
8+
<body>
9+
<h1>JavaScript Serve Example</h1>
10+
<div id="container"></div>
11+
12+
</html>

examples/ts_serve/BUILD

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)