Skip to content

Commit 3877ea7

Browse files
authored
feat: add js library as option for webpack config (#163)
Fix #161 ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: YES - Breaking change (forces users to change their own code or config): NO - Suggested release notes appear below: YES Added option to use js_library for webpack config as alternative to files. ### Test plan - New test cases added
1 parent a6c838d commit 3877ea7

File tree

17 files changed

+1222
-1
lines changed

17 files changed

+1222
-1
lines changed

e2e/loaders_jslib/.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

e2e/loaders_jslib/.bazelrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Import Aspect bazelrc presets
2+
try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc
3+
import %workspace%/../../.aspect/bazelrc/convenience.bazelrc
4+
import %workspace%/../../.aspect/bazelrc/correctness.bazelrc
5+
import %workspace%/../../.aspect/bazelrc/debug.bazelrc
6+
import %workspace%/../../.aspect/bazelrc/javascript.bazelrc
7+
import %workspace%/../../.aspect/bazelrc/performance.bazelrc
8+
9+
### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###
10+
11+
# Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`.
12+
# This file should appear in `.gitignore` so that settings are not shared with team members. This
13+
# should be last statement in this config so the user configuration is able to overwrite flags from
14+
# this file. See https://bazel.build/configure/best-practices#bazelrc-file.
15+
try-import %workspace%/../../.aspect/bazelrc/user.bazelrc

e2e/loaders_jslib/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.bazelversion

e2e/loaders_jslib/.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
2+
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
3+
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
4+
hoist=false

e2e/loaders_jslib/BUILD.bazel

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_library")
2+
load("@aspect_rules_webpack//webpack:defs.bzl", "webpack_bundle")
3+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
4+
load("@npm//:defs.bzl", "npm_link_all_packages")
5+
6+
npm_link_all_packages(name = "node_modules")
7+
8+
js_library(
9+
name = "webpack-config",
10+
srcs = ["webpack.config.cjs"],
11+
deps = [
12+
":node_modules/ts-loader",
13+
],
14+
)
15+
16+
webpack_bundle(
17+
name = "basic",
18+
srcs = [
19+
"src/index.ts",
20+
"tsconfig.json",
21+
],
22+
node_modules = "//:node_modules",
23+
output_dir = True,
24+
webpack_config = ":webpack-config",
25+
)
26+
27+
build_test(
28+
name = "test",
29+
targets = [
30+
":basic",
31+
],
32+
)

e2e/loaders_jslib/MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
###############################################################################
2+
# Bazel now uses Bzlmod by default to manage external dependencies.
3+
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
4+
#
5+
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
6+
###############################################################################

e2e/loaders_jslib/WORKSPACE

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Override http_archive for local testing
2+
local_repository(
3+
name = "aspect_rules_webpack",
4+
path = "../..",
5+
)
6+
7+
# Fetch the Bazel module dependencies
8+
9+
load("@aspect_rules_webpack//webpack:dependencies.bzl", "rules_webpack_dependencies")
10+
11+
rules_webpack_dependencies()
12+
13+
# Fetch and register a nodejs interpreter, if you haven't already
14+
15+
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")
16+
17+
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)
18+
19+
# brought as a dep by webpack ruleset
20+
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
21+
22+
npm_translate_lock(
23+
name = "npm",
24+
no_optional = True,
25+
npmrc = "//:.npmrc",
26+
pnpm_lock = "//:pnpm-lock.yaml",
27+
pnpm_version = "9.0.0",
28+
verify_node_modules_ignored = "//:.bazelignore",
29+
)
30+
31+
load("@npm//:repositories.bzl", "npm_repositories")
32+
33+
npm_repositories()

e2e/loaders_jslib/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"devDependencies": {
3+
"ts-loader": "9.4.2",
4+
"typescript": "4.8.4",
5+
"webpack": "5.76.2",
6+
"webpack-cli": "5.0.1"
7+
},
8+
"pnpm": {
9+
"onlyBuiltDependencies": []
10+
}
11+
}

0 commit comments

Comments
 (0)