GithubHelp home page GithubHelp logo

Comments (10)

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024 2

"The React Native Packager has a built-in option, extraNodeModules, which seems to act as a module alias mapping. I couldn't find much information about this option, but here's the PR where it was added: facebookarchive/node-haste#69. Here's my rn-cli.config.js:"
philikon/ReactNativify#4

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

Im not sure why, but utilizing the react-native-webpack-server's example this works properly, but not when with a react native generated template and following their readme. Tracking here mjohnston/react-native-webpack-server#75

For now, Ive added an example based on their example thats working great.

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

react-native-webpack-server seems poorly supported now, and react is holding steadfast on their packager.
Ive killed the react-native-webpack-server in the example for now, which means no aliasing again.
facebook/react-native#5917 and https://productpains.com/post/react-native/packager-support-resolvealias-ala-webpack/ need your upvotes.

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

This was solved (I dont know what release) by using the default packager and the browser field in package.json

  "browser": {
    "noble": "react-native-ble"
  },

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

Current packager only alias's one level deep it would seem. So we can use var noble = require('noble') in our main file, but if we var Bean = require('ble-bean'); which does its own noble require, it fails out because its trying to us actual noble :(

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

Here is the current issue that is asking for global aliasing. Please bump
facebook/react-native#6253

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

I have a PR in with preliminary deep shim support facebook/react-native#9899 PRs and help wanted.

Also it seems like theres a lot of movement around rn-nodeify, a nifty hack rewriting files locally in order to get around fixing the react native packager. Ive favored this solution in the readmes for now while I continue to work on my solution

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

Todo: Look at https://reactnatve.wordpress.com/2016/06/16/alias-in-react-native/

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

Another day another set of options. I found https://github.com/tleunen/babel-plugin-module-resolver which should allow something like

{
	'presets': ['module:metro-react-native-babel-preset'],
  	'plugins': [
    ['module-resolver', {
	    'extensions': ['.ios.js', '.android.js', '.js', '.json'],
	    'alias': {
	      'noble': 'react-native-ble'
	    }
    }]
  ]
}

However in practice it also recursively rewrites react-native-ble itself so the noble/with-bindings becomes react-native-ble/with-bindings ...
It doesnt have an includes or excludes like say webpack tleunen/babel-plugin-module-resolver#301
but the regex or function
https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md#regular-expressions or
https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md#passing-a-substitute-function might be able to be hacked somehow?

Otherwise @phated has a concept for using the metro field in package.json here

  "metro": {
    "resolver": {
      "resolverMainFields": [
        "react-native",
        "browser",
        "main"
      ]
    }
  }

Then pushing these bindings directly inside of noble and then adding to nobles package.json

  "react-native": {
    "./lib/resolve-bindings.js": "./lib/resolve-bindings"
  },

which could swap in resolve-bindings.ios.js or resolve-bindings.android.js if we move all this code upstream. Though noble needs cross platform code changes swapping events/ and inherits instead of util and events

from react-native-ble.

jacobrosenthal avatar jacobrosenthal commented on July 28, 2024

Oh odd.. you actually dont need any of the metro/react-native key stuff in either project, itll automatically pick up the bindings because noble doesnt specify an extension here
https://github.com/noble/noble/blob/c4cd18a7a429bb832f6c4ca793be3faf9af884e9/index.js#L2

from react-native-ble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.