-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative for "browser" key with higher priority #1694
Comments
I'm wondering why no one responded on this yet. |
i don't understand why a different field would be necessary. the way the browser field works is documented here: https://github.com/defunctzombie/package-browser-field-spec and AFAIK pretty consistently implemented by all major bundlers. |
There are also projects that use The issue is that This is especially true since Bower is basically dead and all of the front-end development is either moving or moved already to NPM. |
What projects use the browser field and don’t follow (at least a subset of) the linked spec? iirc, browserify invented the browser field long before anything else in the ecosystem looked at custom package.json fields - imo that makes any tools that deviate objectively wrong. But I’m interested to hear how it’s being misused :-) |
jQuery used To be clear, I'm not suggesting to drop |
I still don't understand. what sort of conflicts? I don't see how those change anything, were they using the
A key for a ready to use bundle for browsers seems fine, but this is not what the
Exactly why the |
Let's assume you have a project that uses module X as dependency and you use browserify to compile it. But what if you also want to add a key that specifically points to the file that is ready to use in browsers?
Can you name another commonly accepted option for specifying browser bundle in Webpack seems to acknowledge this limitation and supports additional key as there is no reason not to do this, so I'm naturally asking you to add the same thing here and let people avoid this kinds of conflicts. At the end of the day, less project-specific keys in global namespace of |
Why wouldn’t you be able to use browserify in your repo? You can make the “browser” entry point be generated gitignored output, for example. |
If I point |
ah, gotcha. Browserify is really for apps tho, not published packages. Why would you need to publish a bundle? |
Sometimes libraries have dependencies that are primarily targeted at Node.js and not loadable in browser directly, yet I want to make sure users can call my library from browser and don't enforce on them any build system at all, so that then can just One of such libraries I'm developing is https://github.com/nazar-pc/webtorrent-dht and it has |
For users who don’t want a build system at all (those stuck in the previous half decade), your readme - not your package.json - should tell them the path to those built files. The browser field is only for browser build systems to select alternate entry points. |
Put another way, if there’s no build system, you’d have no need of a programmatically identifiable location for the path, since a human would be the one manually including the JS. |
In my case by build system I mean process of converting files from one format to another, bundling files together, etc. There is nothing that prevents you from configuring RequireJS in a way that will allow to just Enforcing someone to use a build system and configure it in particular way just for my small library is a bit rude in my opinion. User of my library should be able to use it with minimal effort regardless of build system or other aspects, the code provided with library package should "just work" in browser. If code can't "just work" - it is a bad code. |
I understand that it might not be your workflow, but I don't really see how proposed change might hurt anyone in any way. |
While i don’t agree with your premise (i think that all npm modules should assume a CJS-compatible build system at this point) j totally agree that your library should be able to offer a drop-in script if you like. However, i think it’s on you to document that in your readme (or your own custom package.json field if you want) for those users who are still consuming libraries via script tag. |
The whole reason I've started this discussion is because I don't want to create yet another custom field for other people to figure out on their own and wanted to use something generally accepted and found a few projects that used But turned out browserify breaks this workflow while not offering any workaround in contrast to other build systems. |
jQuery and d3 use the browser field properly; what projects have you found that use it to mean “pre-bundled entry point that can be dropped in a script tag”? |
Right now D3 doesn't use
I did a mini-research on common fields about ~1.5-2 years ago and wouldn't bother to do it again, but back then there were more projects like that. I think if at this point you are still not convinced to scope browserify's stuff under browserify key (which by the way already exists) even optionally as other projects do, then I'm disappointed and have really nothing to add. |
I don’t see any harm, other than added complexity, of adding such a key - but since all the bundlers and ecosystem tools expect this definition of the “browser” field, i don’t think it would be beneficial for authors - anyone using the browser field for the purpose you describe would end up getting bug reports from the majority of the ecosystem. In other words, adding a “browserify” key won’t change the reality that “browser” already has a permanent meaning, and that for your use case, you’d want a custom field name regardless. |
I've stumbled upon this issue in mwilliamson/mammoth.js#106
browser
key is widely used for defining which file should be used in browser environment. Some tools might use this field optionally, but they also have an alternative which is tool-specific, for instance, in webpack.Could you add support for something like
browserify.browser
with higher priority in addition tobrowser
?The text was updated successfully, but these errors were encountered: