dpdragnev
dpdragnev

Reputation: 2111

Nativescript 6 - environment specific files not working

I just recently migrated my app to NS 6 and I noticed that the environment specific files are not processed properly.

E.g. I have settings.debug.json and settings.release.json. In code, I reference them as import * as settings from '/settings.json' . In NS < 6, this used to work, but now I get an error that that settings.json does not exist.

I have very limited experience with Webpack. Is there a setting I need to configure there for this to work?

Here is my package.json

{
  "name": "<app>",
  "nativescript": {
    "id": "<id>",
    "tns-ios": {
      "version": "6.0.1"
    },
    "tns-android": {
      "version": "6.0.1"
    }
  },
  "description": "",
  "license": "SEE LICENSE IN <your-license-filename>",
  "repository": "<fill-your-repository-here>",
  "dependencies": {
    "moment": "^2.24.0",
    "nativescript-appversion": "^1.4.2",
    "nativescript-geolocation": "5.1.0",
    "nativescript-iqkeyboardmanager": "1.3.0",
    "nativescript-loading-indicator": "2.4.0",
    "nativescript-local-notifications": "3.1.0",
    "nativescript-plugin-firebase": "9.0.2",
    "nativescript-theme-core": "~1.0.4",
    "tns-core-modules": "6.0.1"
  },
  "devDependencies": {
    "nativescript-dev-webpack": "1.0.2",
    "typescript": "3.4.5"
  },
  "readme": "",
  "author": ""
}

Thank you.

Upvotes: 1

Views: 147

Answers (1)

Lochlan
Lochlan

Reputation: 101

You can conditionally load the files using the TNS_ENV variable.

const settings = TNS_ENV !== 'production' ? require('./settings.debug.json') : require('./settings.release.json')

Upvotes: 2

Related Questions