BT

InfoQ Homepage News NativeScript 7 Moves from ES5 to ES2017+

NativeScript 7 Moves from ES5 to ES2017+

Bookmarks

NativeScript 7 aligns with modern JavaScript standards by targeting es2017+. Additionally, it streamlines app configuration by consolidating it in a single file and replaces JavaScriptCore with V8 for iOS apps.

Adopting ES2017, which means that NativeScript will now default to using it as an output target, is mostly motivated by the aim of taking advantage of the improvements it brings to the language, such as the ?? Nullish coalescing operator and optional chaining.

In fact, it was already possible to use ES2017 features supported by TypeScript with previous NativeScript versions, but that meant code was transpiled down to ES5, with potential performance loss and making code harder to step through. For example, this is the case with async/await support, which is now "native" in ES2017, and with the class directive.

The switch to ES2017 is made possible by the adoption of the V8 engine for the iOS platform as well, replacing the JavaScriptCore runtime. This decision levels up JavaScript support on both platforms and reduces maintenance cost, since the NativeScript team will only need to maintain one runtime. In case of incompatibilities or any other issues, you can force NativeScript to use JavaScriptCore by using tns-ios.

Another improvement brought by NativeScript 7 is configuration files consolidation. Until now, app configuration was specified in three different files: the root package.json, nsconfig.json, and another package.json hidden in the source directory to specify any runtime flags. Now, you can just use the new nativescript.config.ts or nativescript.config.js to specify the whole app configuration. The new files enable to specify an app's configuration by using code, so, if you use TypeScript, your nativescript.config.ts file will actually contain a type-safe definition of your project. This is an example of a simple nativescript.config.ts:

import { NativeScriptConfig } from '@nativescript/core';

export default {
  id: 'com.company.app',
  main: 'app.js',
  appResourcesPath: 'App_Resources',
  webpackConfigPath: 'webpack.config.js',
  ios: {
    discardUncaughtJsExceptions: true
  },
  android: {
    discardUncaughtJsExceptions: true,
    v8Flags: '--nolazy --expose_gc',
    "markingMode": "none",
    "suppressCallJSMethodExceptions": false
  }
} as NativeScriptConfig;

On the tooling front, NativeScript CLI has been renamed to ns, although you can also use nsc or the old tns if you prefer it. The new CLI introduces a new ns clean command that can be used to clean up a project's files.

As a final note about migrating existing projects, NativeScript CLI provides the command ns migrate to that aim, but you should make sure all of your plugins are compatible with NativeScript 7 before using it. If you are developing a plugin, make sure you check out the list of [adjustments](https://nativescript.org/blog/nativescript-7-for-plugin-authors/0 that concern you.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.
午夜电影_免费高清视频|高清电视|高清电影_青苹果影院