lightstep-tracer-javascript icon indicating copy to clipboard operation
lightstep-tracer-javascript copied to clipboard

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

Open felixfbecker opened this issue 6 years ago • 4 comments

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.

felixfbecker avatar Dec 14 '18 19:12 felixfbecker

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

austinlparker avatar Dec 17 '18 18:12 austinlparker

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

felixfbecker avatar Dec 17 '18 18:12 felixfbecker

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)?

austinlparker avatar Dec 17 '18 18:12 austinlparker

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.

felixfbecker avatar Dec 17 '18 21:12 felixfbecker