Back to Nativescript

README

packages/webpack5/README.md

9.0.18-core3.6 KB
Original Source
<p align="center"> <a href="https://nativescript.org"> </a> </p> <h1 align="center">@nativescript/webpack</h1> <p align="center"> <b>Webpack configuration for NativeScript apps.</b> </p> <p align="center"> <a href="https://www.npmjs.com/package/@nativescript/webpack"></a> <a href="https://github.com/NativeScript/NativeScript/blob/main/LICENSE"></a> <a href="https://www.npmjs.com/package/@nativescript/webpack"></a> </p> <p align="center"> <a href="https://docs.nativescript.org/configuration/webpack">Documentation</a> ยท <a href="https://docs.nativescript.org/setup/">Environment Setup</a> ยท <a href="https://github.com/NativeScript/NativeScript/blob/main/tools/notes/CONTRIBUTING.md">Contribute</a> ยท <a href="https://nativescript.org/discord">Community</a> </p>

All NativeScript applications are bundled using webpack. This package provides the required configuration to build NativeScript apps with flexibility to customize as needed.

๐Ÿ“ฆ Installation

bash
npm install @nativescript/webpack --save-dev

๐Ÿš€ Quick Start

All new projects come with a base webpack.config.js that's pre-configured:

js
const webpack = require('@nativescript/webpack')

module.exports = (env) => {
  webpack.init(env)

  // Learn how to customize:
  // https://docs.nativescript.org/webpack

  return webpack.resolveConfig()
}

โœจ Features

  • Auto-discovery: Automatically detects your project type (TypeScript, Angular, Vue, React, Svelte)
  • Hot Module Replacement: HMR enabled by default for faster development
  • DotEnv Support: Built-in support for .env files to manage environment variables
  • Bundle Analysis: Generate bundle reports with --env.report
  • Production Optimization: Minification with Terser in production mode

๐Ÿ”ง Global Variables

Useful globally available variables in your app:

VariableDescription
__DEV__true when building in development mode
global.isAndroid / __ANDROID__true when platform is Android
global.isIOS / __IOS__true when platform is iOS
global.isVisionOS / __VISIONOS__true when platform is visionOS
global.__APPLE__true when platform is iOS or visionOS

๐Ÿ“š API

Core Methods

MethodDescription
webpack.init(env)Initialize the internal env object (required)
webpack.chainWebpack(chainFn)Add chain functions to modify config
webpack.mergeWebpack(obj)Merge objects into the final config
webpack.resolveConfig()Resolve the final webpack configuration

๐ŸŽ›๏ธ CLI Flags

FlagDescription
--no-hmrDisable Hot Module Replacement
--env.productionEnable production mode with minification
--env.reportGenerate bundle analysis report
--env.verbosePrint verbose logs and internal config
--env.e2eEnable E2E mode (enables testID property)

๐Ÿ“– Documentation

For complete documentation including configuration examples, visit the webpack configuration guide.

๐Ÿ“„ License

MIT licensed.