Giter Site home page Giter Site logo

Comments (5)

broofa avatar broofa commented on July 16, 2024
// bad
// the entire package is imported
import { v4 } from 'uuid'

The above is the correct syntax, and does in fact allow modern bundlers to "tree shake" out unused code. (See our examples directory for examples of how this works with rollup and webpack.)

If this isn't working for you - i.e. if your bundles contain code for non-v4 versions - please provide a link to a functional example or repository demonstrating the problem and we can take a look. If there's it turns out to be a valid bug we can reopen this issue.

// good
// only imports v4 and necessary dependencies
import v4 from 'uuid/v4'

This is syntax won't work by design. We dropped support for deep imports a few major-versions back (v7... or maybe v8?)

from uuid.

williazz avatar williazz commented on July 16, 2024

If this isn't working for you - i.e. if your bundles contain code for non-v4 versions - please provide a link to a functional example or repository demonstrating the problem and we can take a look. If there's it turns out to be a valid bug we can reopen this issue.

Sure this my team's repo https://github.com/aws-observability/aws-rum-web

As shown below via webpack-bundle-analyzer, we are including other modules such as md5, v1, v3 etc. despite our prod config https://github.com/aws-observability/aws-rum-web/blob/main/webpack/webpack.prod.js

Screenshot 2024-06-19 at 1 39 57 PM

How should this be done instead? Hopefully this is just a config error on our end

from uuid.

williazz avatar williazz commented on July 16, 2024

I've also reviewed https://webpack.js.org/guides/tree-shaking/#root and can't find any issues. We are using the production build, the default minimizer from TerserPlugin, and have marked zero side effects.

from uuid.

broofa avatar broofa commented on July 16, 2024

'Looks like the problem is that you're transpiling to commonjs, which bundlers aren't able to tree shake. While this project does provide commonjs builds, we don't provide the ability to deep import specific versions the way you're suggesting.

While I acknowledge that's a flaw in the existing API for CJS use cases, it's not something I'm interested in addressing at this time.

How should this be done instead?

Consider bundling for ESM. Failing that, I'd suggest switching from uuid to [crypto.randomUUID()](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID), which is broadly supported now.

from uuid.

williazz avatar williazz commented on July 16, 2024

Thank you so much for the two strong callouts

  1. Compiling to commmon js is breaking our tree shaking
  2. Backup strategy to use native crypto package for uuids

from uuid.

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.