Skip to content
Open
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
1 change: 1 addition & 0 deletions .aspect/workflows/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ tasks:
USE_BAZEL_VERSION: '9.0.2'
- format:
queue: aspect-medium
use_args_file: false
- buildifier:
queue: aspect-medium
- finalization:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ npm_package/packages/pkg_d/package.json=1146506398
npm_package/packages/pkg_e/package.json=2046864123
package.json=-2075121688
package_json_module/package.json=-1167380556
pnpm-lock.yaml=-657827575
pnpm-lock.yaml=1115218092
pnpm-workspace.yaml=-1653994035
rspack/package.json=-34571256
runfiles/package.json=-1545884645
stack_traces/package.json=2011229626
vite3/package.json=-1401988763
Expand Down
1 change: 1 addition & 0 deletions examples/.bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm_package/packages/pkg_c/node_modules
npm_package/packages/pkg_d/node_modules
npm_package/packages/pkg_e/node_modules
package_json_module/node_modules
rspack/node_modules
runfiles/node_modules
stack_traces/node_modules
vite3/node_modules
Expand Down
1 change: 1 addition & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ npm.npm_translate_lock(
"//npm_package/packages/pkg_d:package.json",
"//npm_package/packages/pkg_e:package.json",
"//package_json_module:package.json",
"//rspack:package.json",
"//runfiles:package.json",
"//stack_traces:package.json",
"//vite3:package.json",
Expand Down
1,998 changes: 1,966 additions & 32 deletions examples/pnpm-lock.yaml

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions examples/rspack/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer", "js_library", "js_run_binary")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//rspack:@rspack/cli/package_json.bzl", "bin")

npm_link_all_packages()

# The Rspack config. It is natural to represent this as a js_library, because
# it is a JavaScript source file with dependencies.
js_library(
name = "rspack_config",
srcs = ["rspack.config.cjs"],
deps = [":node_modules/@rspack/cli"],
)

# The Rspack binary. We bundle the config into this binary in order to keep all
# JavaScript sources in the runfiles directory. This is important, because if
# we had some sources in the runfiles directory and some outside of it, then
# imports could fail to resolve correctly or we could end up with duplicated
# code.
bin.rspack_binary(
name = "rspack_binary",
data = [":rspack_config"],
# We need to set the arguments here instead of on :rspack_build below for
# two reasons:
# - We can only call rlocationpath here, since this is where we have a
# dependency on :rspack_config.
# - The string "$RUNFILES_DIR" will get written to the launcher script and
# will be evaluated there at run time. This variable evaluation does not
# happen with args set on js_run_binary().
fixed_args = [
"build",
"--config",
"$$RUNFILES_DIR/$(rlocationpath :rspack_config)",
],
)

js_run_binary(
name = "rspack_build",
srcs = ["rspack_entry.js"],
outs = ["rspack/main.bundle.js"],
chdir = package_name(),
tool = ":rspack_binary",
# This option ensures that :rspack_binary is built for the execution
# platform rather than the target platform, which is especially important
# when we are building for a meaningfully different platform such as a
# different OS (see test below).
use_execroot_entry_point = False,
)

js_binary(
name = "rspack_built_binary",
entry_point = "rspack/main.bundle.js",
)

# Make sure we can handle building for a different platform. Let's build an
# image for Linux and another for Mac OS, and at least one of these will
# involve a target platform different from the execution platform.
platform(
name = "linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

platform(
name = "macos",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

js_image_layer(
name = "rspack_image_linux",
binary = ":rspack_built_binary",
platform = ":linux",
)

js_image_layer(
name = "rspack_image_macos",
binary = ":rspack_built_binary",
platform = ":macos",
)

build_test(
name = "build_test",
targets = [
":rspack_image_linux",
":rspack_image_macos",
],
)
8 changes: 8 additions & 0 deletions examples/rspack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "rspack_example",
"private": true,
"devDependencies": {
"@rspack/cli": "1.7.11",
"@rspack/core": "1.7.11"
}
}
12 changes: 12 additions & 0 deletions examples/rspack/rspack.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { defineConfig } = require('@rspack/cli');
const path = require("path");

module.exports = defineConfig({
entry: {
main: './rspack_entry.js',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is rspack resolving this from the current working directory or relative to the config file since the config file will live in a separate bazel-out tree than than this entrypoint

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's resolving it from the current working directory. js_run_binary's working directory is basically "bazel-out/<target platform>/bin/" + chdir where in this case chdir is "rspack".

For the output path below, I did have to replace __dirname with process.cwd() to reflect that the config file is no longer placed in the target platform bin directory.

},
output: {
path: path.resolve(process.cwd(), 'rspack/'),
filename: '[name].bundle.js',
},
});
1 change: 1 addition & 0 deletions examples/rspack/rspack_entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello rspack');
Loading