Skip to content

Instantly share code, notes, and snippets.

@jbms
Last active April 8, 2021 19:42
Show Gist options
  • Save jbms/67e28412418f453c48e1e1207c9925d1 to your computer and use it in GitHub Desktop.
Save jbms/67e28412418f453c48e1e1207c9925d1 to your computer and use it in GitHub Desktop.
nodejs_binary genrule --bazel_patch_module_resolver bug
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
nodejs_binary(
name = "run_postcss",
data = [
"run_postcss.js",
"@npm//postcss",
],
entry_point = ":run_postcss.js",
# templated_args = ["--bazel_patch_module_resolver"],
)
nodejs_binary(
name = "run_esbuild",
data = [
"bundle.ts",
"run_esbuild.js",
"@npm//esbuild",
"@npm//lodash",
],
entry_point = ":run_esbuild.js",
# templated_args = ["--bazel_patch_module_resolver"],
)
genrule(
name = "run_postcss_genrule",
outs = ["empty.txt"],
cmd = "$(execpath :run_postcss) > $@",
tools = [":run_postcss"],
)
genrule(
name = "run_esbuild_genrule",
outs = [
"foo.js",
"foo.js.map",
],
cmd = "$(execpath :run_esbuild) $(OUTS)",
tools = [":run_esbuild"],
)
import throttle from 'lodash/throttle';
const x = throttle(() => console.log('hello'));
x();
x();
{
"name": "rules_nodejs_test",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"colorette": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz",
"integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w=="
},
"esbuild": {
"version": "0.11.6",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.11.6.tgz",
"integrity": "sha512-L+nKW9ftVS/N2CVJMR9YmXHbkm+vHzlNYuo09rzipQhF7dYNvRLfWoEPSDRTl10and4owFBV9rJ2CTFNtLIOiw=="
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"nanoid": {
"version": "3.1.22",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.22.tgz",
"integrity": "sha512-/2ZUaJX2ANuLtTvqTlgqBQNJoQO398KyJgZloL0PZkC0dpysjncRUPsFe3DUPzz/y3h+u7C46np8RMuvF3jsSQ=="
},
"postcss": {
"version": "8.2.9",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.2.9.tgz",
"integrity": "sha512-b+TmuIL4jGtCHtoLi+G/PisuIl9avxs8IZMSmlABRwNz5RLUUACrC+ws81dcomz1nRezm5YPdXiMEzBEKgYn+Q==",
"requires": {
"colorette": "^1.2.2",
"nanoid": "^3.1.22",
"source-map": "^0.6.1"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
}
}
}
{
"name": "rules_nodejs_test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"esbuild": "^0.11.6",
"lodash": "^4.17.21",
"postcss": "^8.2.9"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
const esbuild = require('esbuild');
const path = require('path');
const [, , outputPath, outputMapPath] = process.argv;
async function main() {
const inputPath = path.join(__dirname, 'bundle.ts');
await esbuild.build({
entryPoints: [inputPath],
target: 'es2015',
outfile: outputPath,
preserveSymlinks: true,
bundle: true,
sourcemap: true,
minify: process.argv.includes('--optimize')
});
}
main();
const postcss = require('postcss');
workspace(
name = "rnjstest",
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "f533eeefc8fe1ddfe93652ec50f82373d0c431f7faabd5e6323f6903195ef227",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.3.0/rules_nodejs-3.3.0.tar.gz"],
)
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
npm_install(
name = "npm",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
package_path = "",
symlink_node_modules = False,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment