Add browser field to package.json#60
Add browser field to package.json#60romeovs wants to merge 3 commits intoulid:masterfrom romeovs:patch-2
Conversation
Codecov Report
@@ Coverage Diff @@
## master #60 +/- ##
=======================================
Coverage 92.71% 92.71%
=======================================
Files 2 2
Lines 247 247
Branches 31 31
=======================================
Hits 229 229
Misses 18 18Continue to review full report at Codecov.
|
|
Hey @romeovs, thanks for the contribution! Will do some testing on this, (specifically around tree-shaking) and report back. |
|
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? |
|
Totally agree! Closing. |
This is related to #54.
When building projects using webpack it is common to exclude the
node_modulesfolder 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
ulidpackage does seem to have a transpiled UMD bundle inlib/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:browsermodulemainThe
package.jsonofulidcontains the following relevant fields:So,
moduleis being picked up beforemainby 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 abrowserfield, 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.