ulid / javascript

Universally Unique Lexicographically Sortable Identifier
MIT License
3.04k stars 107 forks source link

Add browser field to package.json #60

Closed romeovs closed 6 years ago

romeovs commented 6 years ago

This is related to #54.

When building projects using webpack it is common to exclude the node_modules folder from transpiration because this causes the build times to sky rocket (especially in projects with big dependency trees).

It should be safe to assume that a package was transpiled so it runs on ES5, to cut down on transpilation times.

The ulid package does seem to have a transpiled UMD bundle in lib/index.umd.js, which webpack supports. The error we saw in #54 (and which I'm seeing in my projects) is due to webpack not picking up on this transpiled bundle, because by default it tries the module alias fields in this order:

  1. browser
  2. module
  3. main

The package.json of ulid contains the following relevant fields:

  "main": "./lib/index.umd.js",
  "module": "./lib/index.js",

So, module is being picked up before main by webpack, causing builds to break. As you've said, adding transpilation (and enabling it for node_modules) should fix the problem. I propose however, that you add a browser field, so by default webpack builds will work as well:

   "main": "./lib/index.umd.js",
+ "browser": "./lib/index.umd.js",
   "module": "./lib/index.js",

I've tested it locally and my webpack build works when these changes are applied.

codecov-io commented 6 years ago

Codecov Report

Merging #60 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #60   +/-   ##
=======================================
  Coverage   92.71%   92.71%           
=======================================
  Files           2        2           
  Lines         247      247           
  Branches       31       31           
=======================================
  Hits          229      229           
  Misses         18       18

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 844e4b0...706b003. Read the comment docs.

alizain commented 6 years ago

Hey @romeovs, thanks for the contribution! Will do some testing on this, (specifically around tree-shaking) and report back.

alizain commented 6 years ago

After some digging, here's what I've found:

Thus, I think the fundamental issues that are raised in this PR have been solved, and this PR is no longer needed. Do you agree?

romeovs commented 6 years ago

Totally agree! Closing.