简体   繁体   中英

how to use a single affected build command in nrwl nx when builders use different options

I have a project with angular and node builders (@angular-builders/custom-webpack:browser and @nrwl/node:build). If I attempt to run a build command that contains arguments that are valid for one, but not the other, I get

nx affected:build --aot

ng run server:build --aot

Unknown option: '--aot'

The angular builder can accept that option, but the node builder cannot. I have resorted to running the affected:build command twice with excludes, but this doesn't scale well as I add other types of builders.

nx affected:build --aot --exclude node-js-app

nx affected:build --exclude angular-js-app1, angular-js-app2

Is there a way to use affected:build across both angular and node projects and be able to use angular specific flags?

Not sure if this is the best or only solution, but this is what I ended up using to work around the issue.

I have configured a custom run command in angular.json in which I have hard coded the specific arguments that I needed for each app or lib. You don't need to hard code it all (see the configuration example) but it our case that was just easier to do.

To use nx affected now you can target the newly created ci-build command: nx affected --target=ci-build --base=origin/master --args="--configuration=production" .

...
   "my-angular-app": {
      "architect": {
        "ci-build": {
          "builder": "@nrwl/workspace:run-commands",
          "options": {
            "commands": [
                "ng build my-angular-app --configuration={args.configuration} --single-bundle --bundleStyles false --keepStyles false"
            ]
          }
        },
...
   "my-node-lib": {
      "architect": {
        "ci-build": {
          "builder": "@nrwl/workspace:run-commands",
          "options": {
            "commands": [
                "ng build my-node-lib --configuration={args.configuration}"
            ]
          }
        }
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM