NodeJS integration w/ the Please build system.
This includes support for the following:
nodejs_toolchain: Easy management of multiple versions of NodeJS.nodejs_npm_package: Incremental NPM packages from a NPM package registry.nodejs_bundle_browser: Builds a browser bundle for the given srcs using the givenbuild_cmd.nodejs_bundle_binary: Builds a binary bundle for the given srcs via the givenbuild_cmdandvercel/pkg.- Advanced:
nodejs_package_json: Generates apackage.jsonfromnodejs_npm_packages. - Advanced:
nodejs_node_modules: Generates anode_modulesfromnodejs_package_json. - Advanced:
nodejs_vercel_pkg_binaries: Downloads Node binaries used byvercel/pkgto generate executables.
This build rule allows you to specify a NodeJS version to download and re-use in most other nodejs_* rules.
This build rule allows you to specify an NPM package to download. You must define all of the packages deps so that we can incrementally download packages. You can use our helper to generate the build rules into your repository, e.g.
# view help
$ ./pleasew run ///nodejs//third_party/binary:please_nodejs -- install --help
# generate rules for the latest version of express and its dependencies into the //third_party/nodejs Please package.
$ ./pleasew run ///nodejs//third_party/binary:please_nodejs -- install express
# generate rules for a specific version of express and its dependencies into the //third_party/nodejs Please package.
$ ./pleasew run ///nodejs//third_party/binary:please_nodejs -- install [email protected]
# generate rules in a structured directory layout under //third_party/nodejs/... for the latest version of express and its dependencies.
$ ./pleasew run ///nodejs//third_party/binary:please_nodejs -- install -s express
# generate rules in under a user-provided Please package for the latest version of express and its dependencies.
$ ./pleasew run ///nodejs//third_party/binary:please_nodejs -- install --pkg_prefix "//examples/esbuild/binary/react-server/third_party/nodejs" expressI highly recommend creating an alias in your .plzconfig for this like so:
[alias "npm-install"]
desc = Runs please_nodejs install to install new dependencies into the repo
cmd = run ///nodejs//third_party/binary:please_nodejs -- install -sThis build rule allows you to build a browser bundle via ESBuild. For example, a React web-application may be built via this rule.
It generates the following subrules:
_dist: A "dist" suitable for uploading to a static hosting site._serve: A local server running the_distoutput powered by Caddy. This may be watched via./pleasew watch --runfor automatic rebuilding of changes. Note: You will need to refresh the webpage to see those changes.
$ ./pleasew watch --run //examples/esbuild/browser/react:react_serve$ ./pleasew watch --run //examples/esbuild/browser/react-typescript-tailwindcss:react-typescript-tailwindcss_serveThis build rule allows you to build a binary bundle via ESBuild and vercel/pkg. For example, a React server application may be built via this rule.
$ ./pleasew run //examples/esbuild/binary/react-server:react-server; .plzconfig
; Support the non *-rules repo name format of Please plugins.
PluginRepo = ["https://github.com/{owner}/{plugin}/archive/{revision}.zip"]
[Plugin "nodejs"]
Target = //third_party/plugins:nodejs
ToolVersion = "v0.0.2" ; Skipping ToolVersion will build the Tool from source.
[Build]
; This links package.json and node_modules to the repo so that IDEs give us type
; hinting. Make sure to add `package.json` and `node_modules/` to your
; `.gitignore`.
LinkGeneratedSources = true# .gitignore
# These are generated via Please.
package.json
node_modules/# //third_party/plugins/BUILD
plugin_repo(
name = "nodejs",
owner = "VJftw",
plugin = "please-nodejs",
revision = "v0.0.2",
)