Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jschaf committed Oct 30, 2024
0 parents commit 602c759
Show file tree
Hide file tree
Showing 17 changed files with 1,626 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.4.0
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

/bazel-*
15 changes: 15 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//:vite/package_json.bzl", "bin")

npm_link_all_packages(name = "node_modules")

ts_config(
name = "tsconfig",
src = "tsconfig.json",
visibility = ["//visibility:public"],
)

bin.vite_binary(
name = "vite",
)
38 changes: 38 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module(
name = "bazel-rules-js-vite",
version = "1.0",
)

bazel_dep(name = "aspect_bazel_lib", version = "2.7.7")
bazel_dep(name = "aspect_rules_js", version = "2.1.0")
bazel_dep(name = "aspect_rules_swc", version = "2.0.1")
bazel_dep(name = "aspect_rules_ts", version = "3.2.1")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_nodejs", version = "6.3.1")

# JavaScript and TypeScript
# =========================

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
node.toolchain(node_version = "20.18.0")

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm", dev_dependency = True)
pnpm.pnpm(
name = "pnpm",
pnpm_version = "9.10.0",
pnpm_version_integrity = "sha512-c6Ka+jag0JLs5Scd5Rd+y/gxjUVOzXATQxMbjrwMGpHEh9pGq3fI5ZbWrPFGHjWUztS+zt+JIbB0+9hlPtcFHA==",
)
use_repo(pnpm, "pnpm")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
no_optional = True,
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")

rules_ts = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True)
rules_ts.deps()
use_repo(rules_ts, "npm_typescript")
811 changes: 811 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Bazel rules-js vite

This repo contains a minimal example of attempting to use Vite with Bazel
rules_js.

To run:

```bash
bazelisk run //:vite -- --help
```

```
$BAZEL_OUT/darwin_arm64-fastbuild/bin/vite_/vite.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/rollup/dist/native.js:63
throw new Error(
^
Error: Cannot find module @rollup/rollup-darwin-arm64. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
at requireWithFriendlyError ($BAZEL_OUT/darwin_arm64-fastbuild/bin/vite_/vite.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/rollup/dist/native.js:63:9)
at Object.<anonymous> ($BAZEL_OUT/darwin_arm64-fastbuild/bin/vite_/vite.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/rollup/dist/native.js:72:76)
... 3 lines matching cause stack trace ...
at Module._load (node:internal/modules/cjs/loader:1104:12)
at cjsLoader (node:internal/modules/esm/translators:346:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:286:7)
at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:473:24) {
[cause]: Error: Cannot find module '@rollup/rollup-darwin-arm64'
```
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "bazel-rules-js-vite",
"private": true,
"type": "module",
"packageManager": "[email protected]",
"pnpm": {
"onlyBuiltDependencies": []
},
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"typescript": "~5.6.2",
"vite": "^5.4.9"
}
}
Loading

0 comments on commit 602c759

Please sign in to comment.