Skip to content

Latest commit

 

History

History

README.md

NativeScript

@nativescript/vite

Vite integration for NativeScript apps.

npm version license

Documentation · Environment Setup · Contribute · Community


Prerequisites

  • NativeScript 9 or higher

Install

npm i @nativescript/vite -D

Quick start (init)

To bootstrap an existing NativeScript app for Vite, run from your app root:

npx nativescript-vite init

This will:

  • Generate a vite.config.ts using the detected project flavor (Angular, Vue, React, Solid, TypeScript, or JavaScript) and the corresponding helper from @nativescript/vite.
  • Add (or update) the following npm scripts in your app package.json:
    • dev:ios
    • dev:android
    • dev:server:ios
    • dev:server:android
    • ios
    • android
  • Add the devDependencies concurrently and wait-on.
  • Add the dependency @valor/nativescript-websockets.
  • Append .ns-vite-build to .gitignore if it is not already present.

After running init, you now have two ways to work with Vite:

  1. HMR workflow
npm run dev:ios
  1. Standard dev workflow (non-HMR)
ns debug ios --no-hmr
ns debug android --no-hmr

Usage

  1. Create vite.config.ts:
import { defineConfig, mergeConfig, UserConfig } from 'vite';
import { typescriptConfig } from '@nativescript/vite';

export default defineConfig(({ mode }): UserConfig => {
	return mergeConfig(typescriptConfig({ mode }), {});
});
  1. Update nativescript.config.ts:
import { NativeScriptConfig } from '@nativescript/core';

export default {
	// add these:
	bundler: 'vite',
	bundlerConfigPath: 'vite.config.ts',
} as NativeScriptConfig;
  1. Enjoy Vite.

Explore More

Check out the NativeScript Vite documentation for more configuration options and features.