Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use esbuild #38

Merged
merged 4 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ gazelle_dependencies()
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("@build_bazel_rules_nodejs//toolchains/esbuild:esbuild_repositories.bzl", "esbuild_repositories")

esbuild_repositories()
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"devDependencies": {
"@babel/preset-typescript": "^7.15.0",
"@bazel/bazelisk": "latest",
"@bazel/buildifier": "4.2.2",
"@bazel/buildifier": "latest",
"@bazel/buildozer": "^4.2.2",
"@bazel/esbuild": "^4.4.0",
"@bazel/ibazel": "latest",
"@bazel/typescript": "^4.4.0",
"@testing-library/react": "^12.1.2",
Expand All @@ -24,13 +25,15 @@
"concurrently": "^6.3.0",
"d3-axis": "^3.0.0",
"d3-scale": "^4.0.2",
"esbuild": "^0.13.8",
"eslint": "^8.1.0",
"eslint-config-next": "11.1.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest-cli": "^27.3.1",
"jsdom": "^18.0.0",
"module-alias": "^2.2.2",
"next": "^12.0.4",
"onchange": "^7.1.0",
"prettier": "^2.4.1",
"ts-node": "^10.4.0",
Expand Down
34 changes: 0 additions & 34 deletions project/cultist/multiplayer/.gitignore

This file was deleted.

69 changes: 14 additions & 55 deletions project/cultist/multiplayer/BUILD
Original file line number Diff line number Diff line change
@@ -1,62 +1,21 @@
load("@npm//next:index.bzl", "next")
load("//:rules.bzl", "ts_lint", "ts_project")
load("//:rules.bzl", "go_binary", "ts_lint", "ts_project")
load("@npm//@bazel/esbuild:index.bzl", "esbuild")
load("@npm//esbuild:index.bzl", run_esbuild = "esbuild")

ts_lint(
name = "lint",
data = glob([
"**/*.ts",
"**/*.js",
]),
)

genrule(
esbuild(
name = "multiplayer",
srcs = glob(
["**/*"],
exclude = ["next.config.ts"],
) + [":next.config.js"],
outs = ["build.tar.gz"],
cmd = """
$(execpath @npm//next/bin:next) build ./project/cultist/multiplayer &&
$(execpath @npm//next/bin:next) export ./project/cultist/multiplayer &&
tar -czvf $@ ./project/cultist/multiplayer/out
""",
exec_tools = [
"@npm//next/bin:next",
"@npm//:node_modules",
] + [],
)

next(
name = "next",
args = ["./cultist/multiplayer"],
data = glob(
["**/*"],
exclude = ["next.config.ts"],
) + [":next.config.js"],
entry_point = "//project/cultist/multiplayer/pages:index.tsx",
minify = True,
output_dir = "es_out",
splitting = True,
deps = ["//project/cultist/multiplayer/pages:pages_ts"],
)

next(
go_binary(
name = "start",
args = [
"./cultist/multiplayer",
"start",
],
data = glob(
["**/*"],
exclude = ["next.config.ts"],
) + [":next.config.js"],
)

ts_project(
name = "config_js",
srcs = ["next.config.ts"],
composite = True,
declaration = True,
incremental = True,
tsconfig = "//:tsconfig_node",
deps = [
"@npm//@types/node",
"@npm//next",
srcs = ["test_server.go"],
embedsrcs = [
":multiplayer",
"//project/cultist/multiplayer/public:index.html",
],
)
6 changes: 0 additions & 6 deletions project/cultist/multiplayer/next-env.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions project/cultist/multiplayer/next.config.ts

This file was deleted.

16 changes: 16 additions & 0 deletions project/cultist/multiplayer/pages/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("//:rules.bzl", "ts_project")

package(default_visibility = ["//project/cultist/multiplayer:__subpackages__"])

ts_project(
name = "pages",
srcs = [
"index.tsx",
],
resolve_json_module = True,
tsconfig = "//:tsconfig_jsx",
deps = [
"@npm//@types/react",
"@npm//react",
],
)
7 changes: 0 additions & 7 deletions project/cultist/multiplayer/pages/_app.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions project/cultist/multiplayer/pages/api/hello.ts

This file was deleted.

80 changes: 3 additions & 77 deletions project/cultist/multiplayer/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,7 @@
import type { NextPage } from 'next';
import Head from 'next/head';
import styles from '../styles/Home.module.css';
import React from 'react';

const Home: NextPage = () => {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta
name="description"
content="Generated by create next app"
/>
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>

<p className={styles.description}>
Get started by editing{' '}
<code className={styles.code}>pages/index.js</code>
</p>

<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation &rarr;</h2>
<p>
Find in-depth information about Next.js features and
API.
</p>
</a>

<a href="https://nextjs.org/learn" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>
Learn about Next.js in an interactive course with
quizzes!
</p>
</a>

<a
href="https://github.com/vercel/next.js/tree/master/examples"
className={styles.card}
>
<h2>Examples &rarr;</h2>
<p>
Discover and deploy boilerplate example Next.js
projects.
</p>
</a>

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h2>Deploy &rarr;</h2>
<p>
Instantly deploy your Next.js site to a public URL
with Vercel.
</p>
</a>
</div>
</main>

<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
</a>
</footer>
</div>
);
const Home = (): React.ReactElement => {
return <div>Hello, world!</div>;
};

export default Home;
4 changes: 4 additions & 0 deletions project/cultist/multiplayer/public/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports_files(
["index.html"],
visibility = ["//project/cultist:__subpackages__"],
)
Binary file removed project/cultist/multiplayer/public/favicon.ico
Binary file not shown.
7 changes: 7 additions & 0 deletions project/cultist/multiplayer/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE HTML>
<head>
<title>Cultist Simulator Multiplayer</title>
</head>
<body>
<script src="index.js"></script>
</body>
4 changes: 0 additions & 4 deletions project/cultist/multiplayer/public/vercel.svg

This file was deleted.

38 changes: 38 additions & 0 deletions project/cultist/multiplayer/test_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"embed"
"fmt"
"io/fs"
"net/http"
)

// below is generated files
//go:embed multiplayer/*
var f embed.FS

//go:embed public/index.html
var index []byte

func Do() (err error) {
nf, err := fs.Sub(f, "multiplayer")
if err != nil {
return
}
fmt.Println("Starting HTTP server @ http://localhost:8080/index.html")
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.FS(nf)))
mux.Handle("/index.html", http.HandlerFunc(func(rw http.ResponseWriter, rq *http.Request) {
rw.Write(index)
}))
return http.ListenAndServe(
":8080",
mux,
)
}

func main() {
if err := Do(); err != nil {
panic(err)
}
}
3 changes: 2 additions & 1 deletion rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ def eslint_test(name = None, data = [], args = [], **kwargs):
["$(location " + x + ")" for x in data],
)

def go_binary(name = None, importpath = None, deps = [], **kwargs):
def go_binary(name = None, embedsrcs = None, importpath = None, deps = [], **kwargs):
_go_binary(
name = name,
deps = deps,
importpath = importpath,
embedsrcs = embedsrcs,
**kwargs
)

Expand Down
Loading