Skip to content

Commit

Permalink
feat: add js library as option for webpack config (#163)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mivr authored Nov 8, 2024
1 parent a6c838d commit 3877ea7
Show file tree
Hide file tree
Showing 17 changed files with 1,222 additions and 1 deletion.
1 change: 1 addition & 0 deletions e2e/loaders_jslib/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions e2e/loaders_jslib/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Import Aspect bazelrc presets
try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc
import %workspace%/../../.aspect/bazelrc/convenience.bazelrc
import %workspace%/../../.aspect/bazelrc/correctness.bazelrc
import %workspace%/../../.aspect/bazelrc/debug.bazelrc
import %workspace%/../../.aspect/bazelrc/javascript.bazelrc
import %workspace%/../../.aspect/bazelrc/performance.bazelrc

### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###

# Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`.
# This file should appear in `.gitignore` so that settings are not shared with team members. This
# should be last statement in this config so the user configuration is able to overwrite flags from
# this file. See https://bazel.build/configure/best-practices#bazelrc-file.
try-import %workspace%/../../.aspect/bazelrc/user.bazelrc
1 change: 1 addition & 0 deletions e2e/loaders_jslib/.bazelversion
4 changes: 4 additions & 0 deletions e2e/loaders_jslib/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
hoist=false
32 changes: 32 additions & 0 deletions e2e/loaders_jslib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_webpack//webpack:defs.bzl", "webpack_bundle")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

js_library(
name = "webpack-config",
srcs = ["webpack.config.cjs"],
deps = [
":node_modules/ts-loader",
],
)

webpack_bundle(
name = "basic",
srcs = [
"src/index.ts",
"tsconfig.json",
],
node_modules = "//:node_modules",
output_dir = True,
webpack_config = ":webpack-config",
)

build_test(
name = "test",
targets = [
":basic",
],
)
6 changes: 6 additions & 0 deletions e2e/loaders_jslib/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
33 changes: 33 additions & 0 deletions e2e/loaders_jslib/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Override http_archive for local testing
local_repository(
name = "aspect_rules_webpack",
path = "../..",
)

# Fetch the Bazel module dependencies

load("@aspect_rules_webpack//webpack:dependencies.bzl", "rules_webpack_dependencies")

rules_webpack_dependencies()

# Fetch and register a nodejs interpreter, if you haven't already

load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

# brought as a dep by webpack ruleset
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
no_optional = True,
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
pnpm_version = "9.0.0",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()
11 changes: 11 additions & 0 deletions e2e/loaders_jslib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"devDependencies": {
"ts-loader": "9.4.2",
"typescript": "4.8.4",
"webpack": "5.76.2",
"webpack-cli": "5.0.1"
},
"pnpm": {
"onlyBuiltDependencies": []
}
}
Loading

0 comments on commit 3877ea7

Please sign in to comment.