I have managed to replace my SERVE with a custom run-command and it's working great apart from some formatting issues.
What I would like to do is replace the build command and get access to the config that is passed by the NG CLI.
Example
ng build --prod
So I would like to be able to pick up the configuration value - which should be set to "production" right?
I know we can pass args using args= which is explained here
https://nx.dev/web/api/workspace/builders/run-commands
but how do we pick up the production config, it would be really great to be able to do this, actually get access to ANY arguments sent in - in a script file
here is what I have
"architect": {
"build": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "./scripts/execute.sh"
}
]
}
},
So in my execute.sh file, i would love to be able to get access to any arguments sent in.
Actually the SH file can be a node file, i don't mind - just as long as I can pick up the arguments sent in via NG CLI i.e. ng buld --prod
The above would allow custom builds without leaving the comfort of ng build.
Thanks in advance.
While not ideal, you can do something like following:
dummy script
// @ts-check
const args = process.argv.slice(2);
main();
function main() {
console.log(args);
}
workspace architect config
you can interpolate arguments within your config
{
"commands": [
{
"command": "node ./tools/scripts/execute.js --prod={args.prod}"
}
]
}
now you can run
nx run your-project:build --args='--prod=true'
which will console log [ '--prod=true' ]
Now you need to implement arguments parser on your own... but this API is not very nice DX.
Wondering if allowing standard argument passing would be such a problem ? cc @jaysoo
I guess so, as that would basically force to run all
commandwithincommandsarray, via CLI provided args, which might cause various unpredicted issues
Thanks @Hotell , I will give it a shot.
the page at https://nx.dev/workspace/plugins_workspace_builders/run-commands has several javascript errors and displays no content
Most helpful comment
the page at https://nx.dev/workspace/plugins_workspace_builders/run-commands has several javascript errors and displays no content