Giter Site home page Giter Site logo

Remove large dependencies about react-use HOT 9 CLOSED

Cretezy avatar Cretezy commented on April 19, 2024 18
Remove large dependencies

from react-use.

Comments (9)

wardoost avatar wardoost commented on April 19, 2024 4

I have been using babel-plugin-import for util packages like this one. Might be good to add something in the docs about this? .babelrc is pretty straight forward:

{
  "plugins": [
    [
      "import", {
        "libraryName": "react-use",
        "libraryDirectory": "lib",
        "camel2DashComponentName": false
      }
    ]
  ]
}

from react-use.

streamich avatar streamich commented on April 19, 2024 2

That would be great! Sorry, for bloating dependencies.

from react-use.

huchenme avatar huchenme commented on April 19, 2024 2

@streamich I believe create-react-app have tree shaking enabled, but still not able to use es module syntax, getting keyboardjs missing error without installing those peerDependencies

import { useAsync } from 'react-use';

Error:

./node_modules/react-use/esm/useKeyboardJs.js
Module not found: Can't resolve 'keyboardjs' in '/Users/chen/projects/github/open_source/hacker-tab-extension/node_modules/react-use/esm'

from react-use.

ctrlplusb avatar ctrlplusb commented on April 19, 2024

Always a great reference site:

https://bundlephobia.com/[email protected]

Could also be a good idea to update the build configuration for this package so that it additionally outputs an ES6 version (pointed at by the module key within package.json).

I do this in my library, for example here is the package output:
https://unpkg.com/[email protected]/

Some build systems (e.g. create-react-app) will then automatically use the ES6 version and treeshake accordingly.

from react-use.

Cretezy avatar Cretezy commented on April 19, 2024

@ctrlplusb bundlephobia is what prompted me to open this ticket, and is preventing us to use this because we don't want to bloat our bundle!

Is there any progress on this?

from react-use.

streamich avatar streamich commented on April 19, 2024

Is there any progress on this?

@Cretezy Well, on Feb 7 you volunteered to make a PR 😄:

If this is a go, I could make the PR with the changes (code & docs) required for this.

from react-use.

Cretezy avatar Cretezy commented on April 19, 2024

Ah damn I had never seen that comment! I'll start working on something when I have free time

from react-use.

Cretezy avatar Cretezy commented on April 19, 2024

Opened PR: #161

from react-use.

streamich avatar streamich commented on April 19, 2024
  1. react-use now has "sideEffects": false set, which should enable Webpack tree-shaking.
  2. See Usage readme if your bundler does not support tree-shaking.
  3. Big dependencies are now in peerDependencies there are few dependencies this library installs but all of those are very minor:
    • copy-to-clipboard — this is just one file and used only if you use copy-to-clipboard hook.
    • nano-css — this should add less than 1Kb to your bundle and only if you use useCss hook.
    • react-fast-compare — this is just one function for deep comparison of objects.
    • react-wait — this is useWait hook, will be included in your bundle only if you use useWait hook.
    • screenfull — used for cross-browser compatibility only in useFullscreen hook.
    • throttle-debounce — just two functions: throttle and debounce.
    • ts-easing — list of easing functions for animations.

from react-use.

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.