-
-
Notifications
You must be signed in to change notification settings - Fork 169
test: add an example of how to invoke Rspack #2846
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
Open
acozzette
wants to merge
2
commits into
aspect-build:main
Choose a base branch
from
acozzette:rspack-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,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", | ||
| ], | ||
| ) |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "name": "rspack_example", | ||
| "private": true, | ||
| "devDependencies": { | ||
| "@rspack/cli": "1.7.11", | ||
| "@rspack/core": "1.7.11" | ||
| } | ||
| } |
This file contains hidden or 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,12 @@ | ||
| const { defineConfig } = require('@rspack/cli'); | ||
| const path = require("path"); | ||
|
|
||
| module.exports = defineConfig({ | ||
| entry: { | ||
| main: './rspack_entry.js', | ||
| }, | ||
| output: { | ||
| path: path.resolve(process.cwd(), 'rspack/'), | ||
| filename: '[name].bundle.js', | ||
| }, | ||
| }); | ||
This file contains hidden or 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 @@ | ||
| console.log('hello rspack'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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/" + chdirwhere in this casechdiris"rspack".For the output path below, I did have to replace
__dirnamewithprocess.cwd()to reflect that the config file is no longer placed in the target platform bin directory.