Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] how to build without running the app #21

Closed
hendrickson-tyler opened this issue May 14, 2021 · 5 comments · Fixed by #28
Closed

[Question] how to build without running the app #21

hendrickson-tyler opened this issue May 14, 2021 · 5 comments · Fixed by #28
Labels
question Further information is requested

Comments

@hendrickson-tyler
Copy link
Contributor

Pretty new to this newfangled Nx workspace thing (coming from the old Angular code sharing method), so I'm trying to get my bearings in this strange land.

Is there an equivalent to running an ns build using this plugin? I see that there are options for ns run, ns debug, and ns clean, but I don't see anything for a regular build. Is this possible currently?

Running ns build in the NativeScript app directory seems to work fine, just wondering if there is a better Nx way to do it.

@mahmoudajawad
Copy link
Contributor

Does this work for you?

npx nx run nativescript-app:build

I believe this should be the method to build the app (for production, without running), but it is failing for me.

@NathanWalker
Copy link
Contributor

The build target represents the general build options. In order to build it you want to combine with the platform you want to build. For example the default workspace.json targets after adding a {N} app to Nx are as follows:

"build": {
      "builder": "@nativescript/nx:build",
      "options": {
        "noHmr": true,
        "production": true,
        "uglify": true,
        "release": true,
        "forDevice": true
      },
      "configurations": {
        "prod": {
          "fileReplacements": [
            {
              "replace": "./src/environments/environment.ts",
              "with": "./src/environments/environment.prod.ts"
            }
          ]
        }
      }
    },
    "ios": {
      "builder": "@nativescript/nx:build",
      "options": {
        "platform": "ios"
      },
      "configurations": {
        "prod": {
          "combineWithConfig": "build:prod"
        }
      }
    },
    "android": {
      "builder": "@nativescript/nx:build",
      "options": {
        "platform": "android"
      },
      "configurations": {
        "prod": {
          "combineWithConfig": "build:prod"
        }
      }
    },

As stated in readme:

Build with an environment configuration enabled (for example, with prod):

Android:

npx nx run <app-name>:android:prod

iOS: (Mac only)

npx nx run <app-name>:ios:prod

When building (you are most often building a release build which the build target options are configured for. You can add different configurations which handle different environment files and can even add other targets with different options to use in combination with each platform target's combineWithConfig option.

I've updated readme to have a Heading above that section (Create a build) to be more clear.

Also note that there's been one webpack5 release build issue we've been working on and you may be affected by it just depending on what your app is using. We anticipate a fix for that issue within the next 2 weeks but there's a workaround solution posted in meantime:
NativeScript/NativeScript#9358

@NathanWalker NathanWalker added the question Further information is requested label May 15, 2021
@NathanWalker NathanWalker changed the title Ability to build without running the app [question] how to build without running the app May 15, 2021
@NathanWalker NathanWalker changed the title [question] how to build without running the app [Question] how to build without running the app May 15, 2021
@hendrickson-tyler
Copy link
Contributor Author

@NathanWalker thanks for your detailed explanation. Using the code above still seems to run the app, however. Looking at the nx/packages/nx/src/builders/build/builder.ts file, it looks like there isn't the ability to create an ns build using nsOptions currently. I've modified this file locally and have been able to add this functionality, so perhaps I'll try to find some time this weekend to create a PR for this.

@kennethkeim
Copy link

I'm running this: npx nx run <app-name>:android:prod
and the builder executes ns debug instead of ns build

@NathanWalker
Copy link
Contributor

NathanWalker commented Jun 17, 2022

@kennethkeim see here: #51 👍 , case 2 likely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
4 participants