问题
I'm just starting with Bazel, I want to create a rule that copies my nodejs application (folder) inside the sandbox, copies other local packages (referenced in package.json using the file://
annotation) and perform a npm install
action.
The output directory should then be a distributable nodejs application with the node_modules/ already set and working (or this is what I want to get).
I've tried by starting over this rule but I can't seem to perform any modification over it and I don't know where to go from there since the logic is pretty hard to follow.
I also tried to start with an easier action but I cannot get it right, especially regarding the local libraries, because it won't allow me declare as glob
any file containing "..".
Can you please give some advice to get started?
If possible I'd also like to know how could I dynamically generate a JSON file, so I'd be able to declare my node dependencies in bazel itself (being able to track them down and centralize their version).
回答1:
this won't be an easy exercise :) It's perfectly doable, and at the end you'll be perfectly comfortable understanding what that rule does :)
I suggest you to read the documentation on writing extensions and custom Skylark rules to start. Be sure to start small and iterate.
It's quite cumbersome to work with directories, you might want to create a tar first. You can also perform npm install if you really want to, but it will have caching and remote execution implications.
And of course, you can generate json in Skylark.
来源:https://stackoverflow.com/questions/44550809/how-to-create-a-custom-rule-to-copy-folder-and-perform-npm-install