Skip to content

wagnerpal/react-native-asset

This branch is 6 commits ahead of unimonkiez/react-native-asset:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

145559b Β· Apr 10, 2024

History

49 Commits
Apr 10, 2024
Jan 25, 2018
Jan 25, 2018
Jan 25, 2018
Feb 28, 2023
Jan 25, 2018
Jul 20, 2019
Apr 10, 2024
Apr 27, 2023
Apr 27, 2023

Repository files navigation

react-native-asset

This is an extended version of the react-native-asset project with support of react-native.config.js sourceDirs

Installation

yarn add --dev wagnerpal/react-native-asset#1.0.0

or

npm install --save-dev wagnerpal/react-native-asset#1.0.0

Link and unlink assets to your react-native project with ease!

Advantages

  • react-native link only supports font files, this tool supports all assets.
  • Unlinking is automatic when you delete an asset, with react-native link, you need to unlink the files manually.
  • Proper link (and unlink) for mp3 (to use with react-native-sound) and ttf files.

Usage

  • Install

    npm install -g react-native-asset
    # or yarn
    yarn global add react-native-asset
  • Add assets to your react-native.config.js as you would with react-native link

    ...
     assets: [
        "./src/font",
        "./src/mp3",
      ];
  • Add platform-specific assets to your react-native.config.js like so:

    ...
    assets: [
      "./src/mp3",
    ],
    iosAssets: [
      "./src/font/ios",
    ],
    androidAssets: [
      "./src/font/android",
    ],
  • This version is considering the react-native.config.js sourceDirs to find the project folders

    ...
    project: {
        android: {
          sourceDir: './apps/android'
        },
        ios: {
          sourceDir: './apps/ios'
        }
      },
  • Run the command and linking + unlinking is automatic!

    react-native-asset

Explanation

With react-native link you have to unlink the files manually, which is hard work.
Instead this library writes link-assets-manifest.json to the root of android and ios folders to keep track of the files which it added, for later removing it for you if missing from your assets!

Parameters

  • -p, --path - path to project, defaults to cwd.
  • -a, --assets - assets paths, for example react-native-asset -a ./src/font ./src/mp3.
  • -ios-a, --ios-assets - ios assets paths, will disable android linking
  • -android-a, --android-assets - android assets paths, will disable ios linking.
  • -n-u, --no-unlink - Not to unlink assets which not longer exists, not recommanded.

Backward compatability

  • to use react-native 0.59 and below, use version 1.1.4

About

Linking and unlinking of assets πŸ”₯

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%