-
Notifications
You must be signed in to change notification settings - Fork 139
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
Add browser support via WebPack, Browserify and similar tools #117
base: master
Are you sure you want to change the base?
Conversation
Hey @3rd-Eden, have had time to give this any thought? I'd be happy to rebase on latest master if you think this is a good approach 👍 |
ping @3rd-Eden |
ping @3rd-Eden |
ping @3rd-Eden |
Apologies for the late response. I don't know if it makes sense to make the library working for browsers because the way that the detection is done is not really suitable for web. It requires you to download a regular expression file that is a whooping 200kb. |
Hmm, that is quite large yes 🤔 I wonder how well it compresses... |
@3rd-Eden Using |
Same here. Would be great to use this library with Angular universal server side rendering, which requires webpack server support. |
@3rd-Eden my use case is a CloudFlare worker where I unfortunately cannot use NPM and so this PR might be useful for cases like that. |
@Rusya44 Right, that seems like a valid usecase. |
Dunno if this is helpful, but I'm using next.js (which in turn uses Webpack), and taking inspiration from this comment on next.js#7755, in my module.exports = {
webpack: (config, { isServer }) => {
// Fixes server-side only packages used by 'useragent'
if (!isServer) {
config.node = {
fs: "empty",
net: "empty",
tls: "empty"
};
}
return config;
}
} ... I also had to |
Also wanting to use this in Cloudflare workers. |
@johnelliott Currently I am using this solution https://github.com/browserslist/browserslist-useragent-regexp |
Hi @3rd-Eden,
This patch moves all the logic for the parsing from
index.js
tolib/parse.js
. The only thing left inindex.js
is the updater part. It then adds abrowser.js
which exportslib/parse.js
directly. Finally abrowser
field is specified in the package.json to let WebPack and friends know which file to use.These are the errors that I'm getting with the currently published version:
I think that this is a much better approach than for me to install
yamlparser
andrequest
since they will then be present in my final bundle.Personally, I would very much prefer to remove the update functionality altogether. I don't think that 1) the API for consuming it are that good (there is no way to know when the new sources are used), 2) it's good practice to modify the javascript files inside node_modules at runtime and 3) not to know exactly what's being deployed since the files are changing when starting up... Anyhow, just my 2¢...
I also see that there are a lot of open issues and pull requests here. If you are low on time or just want a hand I would love to become a maintainer :)