lightstep / lightstep-tracer-javascript

Lightstep distributed tracing library for Node.js and the browser
https://lightstep.com
MIT License
77 stars 66 forks source link

Allow bundling for browser without having to set PLATFORM_BROWSER: true with webpack #138

Open felixfbecker opened 5 years ago

felixfbecker commented 5 years ago

Currently to use in the browser you have to either load the minified bundle, which includes (and duplicates) dependencies that I may already have in my bundle, or bundle with webpack and set PLATFORM_BROWSER to true. Parcel doesn't have an option to inject these global variables or tree-shake with them, so importing lightstep-tracer and bundling with parcel will always end up bundling both platform implementations and running the Node implementation.

austinlparker commented 5 years ago

Does this also happen if you import lightstep-tracer/browser? Not super familiar with Parcel.

felixfbecker commented 5 years ago

No, but then I am using all the bundled dependencies in the browser bundle instead of letting the bundler resolve, deduplicate and tree-shake them, and giving me the power to update dependencies for security fixes like https://github.com/lightstep/lightstep-tracer-javascript/issues/136

austinlparker commented 5 years ago

Ahh, ok, huh. Yeah, I think this is a pretty sane request. I'm not really sure what the right way to go about doing this would be though - split the package into a browser and non-browser version (pre-minification)?

felixfbecker commented 5 years ago

package.json supports a browser field that is like a main field used when bundling for browsers. But it would require a bit of restructuring of the current code base with the platform abstraction.