plausible / plausible-tracker

Frontend library to interact with Plausible Analytics
https://github.com/plausible/plausible-tracker
MIT License
215 stars 50 forks source link

Usage of Node `process` module pulls in ~3KB shim when building #57

Open Daniel15 opened 1 year ago

Daniel15 commented 1 year ago

Versions

Describe the bug

I'm using Parcel to build the JS for one of my sites. This code in the Plausible tracker: https://github.com/plausible/plausible-tracker/blob/c0b87d997d839938c23023d35bac0d6683635bbc/src/lib/tracker.ts#L285-L296

Causes Parcel to pull in a ~3KB (minified) shim for the Node.js process module. This is the code that gets bundled: https://github.com/defunctzombie/node-process/blob/master/browser.js

This can be avoided with the following Parcel config in package.json:

  "alias": {
    "process": false
  }

but this shouldn't be necessary.

Expected behavior

Tracker should be as lightweight as possible and not pull in unnecessary shims. Since the code causing this issue is only for testing, it shouldn't exist at all in the production build of the library. Potentially this code could be implemented using a mock in the test, rather than modifying the library itself to perform differently under test.

Steps to reproduce

Steps: Create analytics.js, for example:

import Plausible from 'plausible-tracker';

const {trackPageview, enableAutoOutboundTracking} = new Plausible({
  apiHost: 'https://example.com',
  trackLocalhost: true,
});

trackPageview();
enableAutoOutboundTracking();

Run parcel on it, e.g.

yarn install parcel
.\node_modules\.bin\parcel build analytics.js

Observe the resulting dist/analytics.js file.

Your Environment

N/A

Barbapapazes commented 9 months ago

Hello,

Since this package have not been update for two years, I made a fork.

I rewrite the tracker to be more modular and I fix this issue.

https://github.com/Barbapapazes/plausible-tracker