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
Support for browser usage out-of-the-box (webpack) #3
Comments
@renatodeleao thanks for the comprehensive issue / feature request! The module was originally designed to be used on the server side, but it might be a good idea to make this also work within the browser. I'll check the links you provided, to be honest I'm not really a frontend guy, so this might take a while. |
I‘ll provide a browserify bundle with the upcoming 0.2.0 release. |
This should be fixed in version |
Well don't worry, to be honest i'm not really a server/backend guy :) So It does work (thanks 🙌), but allow me to add some points:
Thats all, thanks once again, i'll leave a PR for this in case you're interested! |
Hi, thanks for taking the time to make this!
My usecase is simple: on a webpage, I’m using your module to compare and get more details after a response from a ping (xhr) to a server, which is returning me the three letters edge location prefix for the closest PoP in a custom header. Then I do some fancy unrelated ui stuff based on it and the other details that your module provide (coordinates, names, count) .
The problem is that, without a specific webpack config, importing your module throws an error because you use node's
fs.readFileSync
atindex.js
, which doesn’t work in browser.Workaround used
Using webpack’s
transform-loader
(browserify transforms) withbrfs
plugin (wich inlines content fromfs.readFileSync()
calls) we can workaround the problem and use your module just fine. If you do not plan to support the browser environment, maybe a reference in docs will suffice.- As seen on pdfKit: https://github.com/huy-nguyen/webpack-and-pdfkit
- Loader: https://github.com/webpack-contrib/transform-loader
- Plugin: https://www.npmjs.com/package/brfs
Possible solution
If there’s the intention of making this package compatible with client side, i would say that a build step could be added to distribute a bundled/minified version of the package with locations inlined as an object (similar to the workaround config does). Decision on make it default or a separate bundle and corresponding named export is up to you.
Other Workarounds and references found in the wild
might be useful when researching how others dealt with the problem.
Cheers, thanks for your time
✌️ ☮️
The text was updated successfully, but these errors were encountered: