After installing the package locally or via npm, the CLI should be available.
If you've installed the package locally using one of these methods:
-
Yarn Workspaces (already set up in this project):
yarn prepare # Build the package first yarn example start -
npm/yarn link:
# In the package directory npm link # In your project npm link react-native-smart-assets
-
Local file path:
{ "dependencies": { "react-native-smart-assets": "file:../path/to/awesome-library" } }
After installation, you can run:
# Using npx (recommended)
npx react-native-smart-assets generate
# Or directly if installed globally
react-native-smart-assets generate
# Or using the full path to the built file
node node_modules/react-native-smart-assets/lib/module/cli/index.js generatenpx react-native-smart-assets generate [options]Options:
--assets-dir <path>: Custom assets directory (default:assets)--output-dir <path>: Custom output directory (default:assets)--format <format>: Output format:typescriptorjavascript(default:typescript)
Example:
npx react-native-smart-assets generate --assets-dir ./src/assets --output-dir ./src/assetsnpx react-native-smart-assets validate [options]Checks for:
- Missing files
- Invalid file formats
- Duplicate asset names
- Missing variants
npx react-native-smart-assets stats [options]Shows asset counts, types, and distribution.
npx react-native-smart-assets watch [options]Automatically regenerates the asset registry when files change.
-
Make sure the package is built:
cd /path/to/awesome-library npm run prepare -
If using local installation, try:
# Use the full path node node_modules/react-native-smart-assets/lib/module/cli/index.js generate # Or reinstall npm install
-
If using npx, make sure the package is in your
node_modules:npm install react-native-smart-assets # or yarn add react-native-smart-assets
Make sure the CLI file is executable:
chmod +x node_modules/react-native-smart-assets/lib/module/cli/index.jsThe CLI uses ES modules. Make sure you're using Node.js 14+ and that your project supports ES modules.
# 1. Create assets directory
mkdir assets
mkdir assets/images
mkdir assets/icons
# 2. Add your assets
# (copy your images and SVG files)
# 3. Generate the registry
npx react-native-smart-assets generate
# 4. Use in your code
import { Asset } from 'react-native-smart-assets';
import { setAssetRegistry } from 'react-native-smart-assets';
import * as Assets from './assets';
setAssetRegistry(Assets.ASSETS);
<Asset name="images/logo" size={100} />