NativeScript / nx

NativeScript for Nx.
Other
61 stars 15 forks source link

[Question] Is "ns preview" supported in {N} nx library? #74

Open juantot9 opened 7 months ago

juantot9 commented 7 months ago

Hello!

I am new using {N} and I wanted to start a project using nx for an angular crossplatform app. After starting the project with nx and working correctly following the documentation, I was wondering if there is any way to use the preview feature with nx commands.

I tried to search within the docs and code but couldn't find any way to do it. It would be awesome if this exists with a command like nx run <project-name>:preview or something similar. Thank you in advance!

NathanWalker commented 7 months ago

Hi @juantot9 Yes there is. We don't include one by default but you can add this to your apps/nativescript-myapp/project.json:

"preview": {
      "executor": "nx:run-commands",
      "options": {
        "commands": [
          "ns preview"
        ],
        "parallel": false,
        "cwd": "apps/nativescript-myapp"
      }
    },

Also if you just generated your workspace, you'll notice it used newly released Nx 18. We'll release a @nativescript/nx sometime this month to match 18 major but just note that Nx 18 will init a workspace with typescript ~5.3.0 and when you generate a Angular based NativeScript app you would get Angular 16 dependencies added which require typescript ~5.2.0.

You can change typescript or what I would recommend is just using latest Angular 17 and sticking with typescript ~5.3.0 (which Nx 18 sets up). So your dependencies would look like this:

  "dependencies": {
    "@angular/animations": "^17.0.0",
    "@angular/common": "^17.0.0",
    "@angular/compiler": "^17.0.0",
    "@angular/core": "^17.0.0",
    "@angular/forms": "^17.0.0",
    "@angular/platform-browser": "^17.0.0",
    "@angular/platform-browser-dynamic": "^17.0.0",
    "@angular/router": "^17.0.0",
    "@nativescript/core": "~8.6.0",
    "@nativescript/angular": "^17.0.0",
    "nativescript-theme-core": "~1.0.4",
    "rxjs": "~7.8.0",
    "zone.js": "^0.14.0"
  },
"devDependencies": {
    "@angular-devkit/build-angular": "^17.0.0",
    "@angular/compiler-cli": "^17.0.0",
    "@nativescript/nx": "^17.1.0",
    "@nativescript/webpack": "~5.0.0",
    "@nativescript/types": "~8.6.0",
    "@ngtools/webpack": "^17.0.0"
    "@nx/js": "18.0.3",
    "@nx/workspace": "18.0.3",
    "@swc-node/register": "~1.6.7",
    "@swc/core": "~1.3.85",
    "@swc/helpers": "~0.5.2",
    "nx": "18.0.3",
    "prettier": "^2.6.2",
    "sass": "^1.32.0",
    "typescript": "~5.3.0"
  },

Hope that helps.

NathanWalker commented 7 months ago

Oh also keep in mind current 'NativeScript Preview' app on appstore and google play needs @nativescript/core "~8.5.0".

Some updates will be posted this month which will work with ~8.6.0 and higher.

juantot9 commented 7 months ago

Hello @NathanWalker ! Thank you so much for all this information, I will try to do it in a few hours and see what happens! Seems pretty easy to do! Also, I updated the libraries, that were by defect in v16. I will let you know if it works! I had some problems figuring out that the problem with making the preview work was the version, a good folk helped me on the discord channel hehe. Again, thank you so much!