react-native-optimizer
v0.0.31
Published
π Zero-config React Native & Node.js optimizer. Find unused imports, dead code, analyze bundle size. Works with Expo, Metro, TypeScript. Fast AST parsing, HTML reports, CI/CD ready. Boost performance instantly!
Maintainers
Keywords
Readme
π React Native Optimizer
Production-grade CLI tool and library for optimizing React Native & Node.js projects
Automatically detect unused code, analyze dependencies, optimize bundle sizes, and generate comprehensive reports with zero configuration.
β‘ Quick Start β’ β¨ Features β’ οΏ½ API β’ π€ Contributing
β‘ Quick Start
# Run instantly with npx (recommended)
npx react-native-optimizer analyze
# Or install globally
npm install -g react-native-optimizer
rnopt analyze
# Or install as project dependency
npm install --save-dev react-native-optimizerThat's it! Get comprehensive insights into your React Native or Node.js project in seconds with zero configuration.
π React Native Optimizer
Analyzing project: my-awesome-app
Project type: π± react-native
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Analysis Results (4.3s)
Files: 247 | Lines: 15,432 | Size: 892.4 KB
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β οΈ Found Issues
π 3 files with unused imports
ποΈ 2 unused files (3.2 KB)
π¦ 2 unused packages (828 KB)
β οΈ 1 deprecated package
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π‘ Quick Wins
β’ Remove unused imports β cleaner code
β’ Delete unused files β save 3.2KB
β’ Uninstall unused packages β save 828KB
β’ Update deprecated packages β improve security
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β¨ 8 optimization opportunities found!
π Interactive report: ./optimizer-report.htmlπ― Why Use This?
- π Zero Configuration - Works out of the box with React Native & Node.js projects
- β‘ Lightning Fast - Powered by Babel AST parsing for accurate analysis
- π Beautiful Reports - Interactive HTML reports with charts and actionable insights
- π§ CI/CD Ready - Perfect for automated code quality checks
- π‘οΈ Safe & Secure - Read-only analysis, never modifies your code
- π¦ Production Tested - Used by teams to optimize real-world applications
β¨ Key Features
π Comprehensive Analysis
- Unused Import Detection - Find and remove unused imports with precise AST parsing
- Dead Code Elimination - Identify unused files safe for removal
- Package Dependency Analysis - Detect unused and deprecated packages
- Bundle Size Optimization - Analyze build outputs and identify bloat
π Professional Reporting
- Interactive HTML Reports - Beautiful visualizations with charts and metrics
- JSON Export - Perfect for CI/CD integration and automation
- Actionable Insights - Get specific commands to fix issues
π Framework Intelligence
- React Native Aware - Handles Metro, Expo, and native dependencies
- Node.js Optimized - Supports Express, NestJS, Prisma, and more
- Zero Configuration - Works out of the box with smart defaults
- Framework Safety - Never flags critical framework dependencies
π¦ Installation
Global Installation (Recommended)
npm install -g react-native-optimizerProject Installation
npm install --save-dev react-native-optimizer
# or
yarn add --dev react-native-optimizerUse with npx (No Installation)
npx react-native-optimizer analyzeπ Usage
Basic Commands
# Analyze current project (includes package analysis + HTML report)
npx rnopt analyze
# Quick analysis without HTML report
npx rnopt analyze --no-html
# Full analysis with build insights
npx rnopt analyze --build --verbose
# Save results to JSON for CI/CD
npx rnopt analyze --output report.json --no-htmlCLI Options
| Option | Description | Default |
|--------|-------------|---------|
| --build | Include bundle size analysis | false |
| --no-html | Skip HTML report generation | false |
| --no-packages | Skip package dependency analysis | false |
| --verbose | Show detailed analysis logs | false |
| --output <file> | Save JSON report to file | - |
| --type <type> | Force project type (react-native, node) | auto-detect |
π» API Usage
TypeScript/ES6
import { optimizeProject, generateHtmlReport } from 'react-native-optimizer';
// Simple analysis
const result = await optimizeProject('./my-project');
console.log(`Found ${result.unusedImports.length} unused imports`);
// Generate HTML report
const reportPath = generateHtmlReport(result, './my-project');
console.log(`Report saved to: ${reportPath}`);JavaScript/CommonJS
const { optimizeProject } = require('react-native-optimizer');
optimizeProject('./my-project')
.then(result => {
console.log('Analysis complete:', {
unusedImports: result.unusedImports.length,
unusedFiles: result.unusedFiles.length,
unusedPackages: result.packageAnalysis?.unusedPackages.length || 0
});
})
.catch(console.error);Main Functions
optimizeProject(projectPath, options?)
interface OptimizeOptions {
includeBuildAnalysis?: boolean; // Bundle size analysis
includePackageAnalysis?: boolean; // Package analysis (default: true)
}
interface OptimizerResult {
success: boolean;
projectType: 'react-native' | 'node' | 'unknown';
projectStats: { totalFiles: number; totalLines: number; totalSize: number; };
unusedImports: Array<{ file: string; imports: string[]; }>;
unusedFiles: Array<{ path: string; size: number; }>;
packageAnalysis?: {
unusedPackages: Array<{ name: string; version: string; size: number; }>;
deprecatedPackages: Array<{ name: string; reason: string; }>;
};
suggestions: string[];
}generateHtmlReport(result, projectPath, outputPath?)
Generates an interactive HTML report from analysis results.
π§ CI/CD Integration
GitHub Actions
name: Code Quality
on: [push, pull_request]
jobs:
optimize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run React Native Optimizer
run: npx react-native-optimizer analyze --output report.json --no-html
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: optimization-report
path: report.jsonGitLab CI
code_quality:
image: node:18
script:
- npm ci
- npx react-native-optimizer analyze --output gl-code-quality-report.json --no-html
artifacts:
reports:
codequality: gl-code-quality-report.jsonJenkins Pipeline
pipeline {
agent any
stages {
stage('Code Quality') {
steps {
sh 'npm ci'
sh 'npx react-native-optimizer analyze --output report.json --no-html'
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: '.',
reportFiles: 'report.json',
reportName: 'Optimization Report'
])
}
}
}
}βοΈ Configuration
Project Configuration (.optimizerrc.json)
{
"buildAnalysis": {
"enabled": false,
"bundleThreshold": 1024
},
"packageAnalysis": {
"enabled": true,
"checkDeprecated": true
},
"excludePatterns": [
"**/*.test.*",
"**/fixtures/**",
"**/__mocks__/**",
"**/dist/**",
"**/build/**"
],
"logLevel": "INFO"
}Package.json Configuration
{
"reactNativeOptimizer": {
"excludePatterns": ["**/test/**"],
"packageAnalysis": { "enabled": true },
"logLevel": "WARN"
}
}Environment Variables
OPTIMIZER_LOG_LEVEL=DEBUG # Set log verbosity
OPTIMIZER_NO_COLOR=true # Disable colored output
OPTIMIZER_MAX_FILES=10000 # Limit files processedπ What Gets Analyzed
Supported Project Types
- React Native - Metro configs, platform directories, native dependencies
- Node.js - Express apps, APIs, microservices, CLI tools
- Universal - Any TypeScript/JavaScript project
Code Analysis
- Included:
.js,.jsx,.ts,.tsxsource files, import/export patterns - Excluded: Test files, config files, build outputs, type definitions
- Smart Filtering: Automatically excludes framework-specific files
Package Analysis
- Unused Detection - Scans source code for actual package usage
- Deprecation Check - Queries npm registry for package status
- Size Calculation - Estimates potential space savings
β FAQ
Q: Does this tool modify my code?
A: No, it's read-only analysis. We never modify your source code.
Q: How accurate is the unused code detection?
A: Very accurate! We use Babel AST parsing instead of regex for precise analysis.
Q: Can I use this in CI/CD pipelines?
A: Absolutely! Many teams use it to fail builds with too many issues.
Q: Does it work with monorepos?
A: Yes! Run it in each package directory or at the root level.
Q: Is it safe for production projects?
A: Yes, it's completely safe and used by production teams worldwide.
π€ Contributing
We love contributions! Here's how to get started:
# 1. Fork & clone the repo
git clone https://github.com/junaidsaleemtkxel/react-native-optimizer
cd react-native-optimizer
# 2. Install dependencies
npm install
# 3. Build & test
npm run build
npm test
# 4. Test your changes
npx rnopt analyze ./test-projectSee our Contributing Guide for detailed guidelines.
π Community & Support
- π Report Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π Roadmap: Project Roadmap
- π§ Email: [email protected]
π License
MIT Β© Junaid Saleem
π Show Your Support
Found this useful? Help us grow the community:
- β Star this repo if it helped optimize your project
- π¦ Share on Twitter with
#ReactNativeOptimizer - π Write a review or blog post about your experience
- π€ Contribute improvements and new features
β Star on GitHub β’ π¦ View on npm β’ π Read the Docs
Built for developers, by developers π
