| load("@aspect_rules_js//contrib/nextjs:defs.bzl", "nextjs_standalone_build", "nextjs_standalone_server") |
| load("@aspect_rules_js//js:defs.bzl", "js_image_layer", "js_library") |
| load("@bazel_lib//lib:write_source_files.bzl", "write_source_files") |
| load("@bazel_skylib//rules:build_test.bzl", "build_test") |
| load("@npm//:defs.bzl", "npm_link_all_packages") |
| load("@npm//nextjs:next/package_json.bzl", next_bin = "bin") |
| load("@rules_shell//shell:sh_test.bzl", "sh_test") |
| |
| npm_link_all_packages() |
| |
| # The nextjs binary target to used by nextjs:defs.bzl |
| next_bin.next_binary( |
| name = "next_js_binary", |
| visibility = ["//visibility:public"], |
| ) |
| |
| js_library( |
| name = "lib", |
| srcs = glob([ |
| "src/**", |
| "public/**", |
| ]), |
| deps = [ |
| ":node_modules/next", |
| ":node_modules/react", |
| ":node_modules/react-dom", |
| ], |
| ) |
| |
| js_library( |
| name = "nextjs-css", |
| srcs = [ |
| "postcss.config.mjs", |
| ], |
| deps = [ |
| ":node_modules/@tailwindcss/postcss", |
| ":node_modules/tailwindcss", |
| ], |
| ) |
| |
| # The standard nextjs build/start/dev workflow |
| # nextjs( |
| # name = "app", |
| # srcs = [ |
| # "jsconfig.json", |
| # ":nextjs-css", |
| # ":lib", |
| # ], |
| # config = "next.config.mjs", |
| # next_js_binary = ":next_js_binary", |
| # ) |
| |
| # A standalone nextjs build |
| nextjs_standalone_build( |
| name = "standalone", |
| srcs = [ |
| "jsconfig.json", |
| ":lib", |
| ":nextjs-css", |
| ], |
| config = "next.standalone.mjs", |
| next_js_binary = ":next_js_binary", |
| silent_on_success = False, |
| ) |
| |
| # A standalone server |
| nextjs_standalone_server( |
| name = "server", |
| app = ":standalone", |
| data = [ |
| ":node_modules/next", |
| ":node_modules/react", |
| ], |
| ) |
| |
| 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 = "server_linux", |
| binary = ":server", |
| platform = ":linux", |
| ) |
| |
| js_image_layer( |
| name = "server_macos", |
| binary = ":server", |
| platform = ":macos", |
| ) |
| |
| build_test( |
| name = "cross_platform_build_test", |
| targets = [ |
| ":server_linux", |
| ":server_macos", |
| ], |
| ) |
| |
| # Verify next (which has optional platform/os specific dependencies) can be built |
| build_test( |
| name = "next_build_test", |
| targets = [":node_modules/next"], |
| ) |
| |
| # Verify that the standalone server actually starts and serves HTTP. |
| sh_test( |
| name = "server_test", |
| srcs = ["server_test.sh"], |
| args = ["$(rootpath :server)"], |
| data = [":server"], |
| ) |
| |
| write_source_files( |
| name = "write_next_links_defs", |
| files = { |
| "snapshots/next_links_defs.bzl": "@npm__next__15.2.6_1816342077__links//:defs.bzl", |
| }, |
| tags = [ |
| "skip-on-bazel8", |
| "skip-on-bazel9", |
| ], |
| ) |