-
-
Notifications
You must be signed in to change notification settings - Fork 170
feat: streamline invocation of binaries from npm and update examples #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
Merged
+2,177
−94
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
18f5661
test: add an example of how to invoke Rspack
acozzette 390703b
Try to fix failing formatter in CI
acozzette a7db212
Update calls to rollup to use use_execroot_entry_point = False
acozzette 7bd2282
refactor: move bundler configs into tool runfiles for exec/target pla…
acozzette 44c599f
Run buildifier
acozzette 4326a4e
Revert workaround for CI formatting issue
acozzette da9c3b7
Fix webpack_cli example
acozzette 90d27bd
refactor(vite3): move config into tool runfiles for exec/target platf…
acozzette 6aefa33
refactor(vite6): move config into tool runfiles for exec/target platf…
acozzette 4a700c5
refactor(node-patches): move babel config into tool runfiles for exec…
acozzette ec08b1e
Simplify things
acozzette 18b3066
buildifier
acozzette 55eacd2
cleanup
acozzette 2f487cb
fix
acozzette f878a57
Remove use_execroot_entry_point = False where possible
acozzette 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
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,77 @@ | ||
| load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer", "js_library") | ||
| 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"], | ||
| ) | ||
|
|
||
| bin.rspack( | ||
| name = "rspack_build", | ||
| srcs = ["rspack_entry.js"], | ||
| outs = ["rspack/main.bundle.js"], | ||
| chdir = package_name(), | ||
| # The config should be provided via the data parameter so that it becomes | ||
| # part of the runfiles of the Rspack binary. | ||
| data = [":rspack_config"], | ||
| # Since :rspack_config is a dependency of the binary, we need to reference | ||
| # it here in fixed_args. The fixed_args param applies to the js_binary | ||
| # whereas args applies to js_run_binary. | ||
| fixed_args = [ | ||
| "build", | ||
| "--config", | ||
| "$$RUNFILES_DIR/$(rlocationpath :rspack_config)", | ||
| ], | ||
| use_execroot_entry_point = False, | ||
|
jbedard marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| 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', | ||
|
acozzette marked this conversation as resolved.
|
||
| }, | ||
| 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'); |
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
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 |
|---|---|---|
| @@ -1,31 +1,37 @@ | ||
| load("@npm//:defs.bzl", "npm_link_all_packages") | ||
| load("@npm//js/private/coverage/bundle:rollup/package_json.bzl", rollup_bin = "bin") | ||
| load("//js:defs.bzl", "js_library") | ||
|
|
||
| npm_link_all_packages() | ||
|
|
||
| js_library( | ||
| name = "config", | ||
| srcs = ["rollup.config.mjs"], | ||
| deps = [ | ||
| ":node_modules/@rollup/plugin-commonjs", | ||
| ":node_modules/@rollup/plugin-json", | ||
| ":node_modules/@rollup/plugin-node-resolve", | ||
| ], | ||
| ) | ||
|
|
||
| rollup_bin.rollup( | ||
| name = "bundle", | ||
| srcs = [ | ||
| "c8.js", | ||
| "package.json", | ||
| "rollup.config.mjs", | ||
| ":node_modules/@rollup/plugin-commonjs", | ||
| ":node_modules/@rollup/plugin-json", | ||
| ":node_modules/@rollup/plugin-node-resolve", | ||
| ":node_modules/c8", | ||
| ], | ||
| outs = [ | ||
| "bundle.js", | ||
| ], | ||
| args = [ | ||
| outs = ["bundle.js"], | ||
| chdir = package_name(), | ||
| data = [":config"], | ||
| fixed_args = [ | ||
|
acozzette marked this conversation as resolved.
|
||
| "c8.js", | ||
| "--config", | ||
| "rollup.config.mjs", | ||
| "$$RUNFILES_DIR/$(rlocationpath :config)", | ||
| "--format", | ||
| "cjs", | ||
| "--file", | ||
| "bundle.js", | ||
| ], | ||
| chdir = package_name(), | ||
| visibility = ["//js/private/coverage:__pkg__"], | ||
| ) | ||
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 |
|---|---|---|
| @@ -1,26 +1,32 @@ | ||
| load("@npm//:defs.bzl", "npm_link_all_packages") | ||
| load("@npm//js/private/devserver/src:rollup/package_json.bzl", rollup_bin = "bin") | ||
| load("//js:defs.bzl", "js_library") | ||
|
|
||
| npm_link_all_packages() | ||
|
|
||
| js_library( | ||
| name = "config", | ||
| srcs = ["rollup.config.mjs"], | ||
| deps = [":node_modules/@rollup/plugin-node-resolve"], | ||
| ) | ||
|
|
||
| rollup_bin.rollup( | ||
| name = "js_run_devserver_bundle", | ||
| srcs = [ | ||
| "js_run_devserver.mjs", | ||
| "rollup.config.mjs", | ||
| ":node_modules/@rollup/plugin-node-resolve", | ||
| "//js/private/watch", | ||
| ], | ||
| outs = ["bundle.mjs"], | ||
| args = [ | ||
| chdir = package_name(), | ||
| data = [":config"], | ||
| fixed_args = [ | ||
| "js_run_devserver.mjs", | ||
| "--config", | ||
| "rollup.config.mjs", | ||
| "$$RUNFILES_DIR/$(rlocationpath :config)", | ||
| "--format", | ||
| "es", | ||
| "--file", | ||
| "bundle.mjs", | ||
| ], | ||
| chdir = package_name(), | ||
| visibility = ["//js/private/devserver:__pkg__"], | ||
| ) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.