googleanalytics / autotrack

Automatic and enhanced Google Analytics tracking for common user interactions on the web.
Other
4.93k stars 563 forks source link

Reduce bundle size by making autotrack build dependencies optional or split into new package #231

Open ZhangYiJiang opened 6 years ago

ZhangYiJiang commented 6 years ago

Currently autotrack includes all of the tools needed to build a custom bundle as direct dependencies. This makes it easy to build since users just have to run npm install and all of the build dependencies will be automatically installed, but for users who already use their own bundler and just needs the source, the additional dependencies do add quite a bit of size to node_modules -

$ yarn why autotrack 
yarn why v1.7.0
info Disk size without dependencies: "1.08MB"
info Disk size with transitive dependencies: "15.86MB"

16MB is not a huge amount of disk space, but it is a lot relative to the amount of actual code the package is exporting (more than 16x), and completely unused for many people. A simple way to fix this is to make all of the package dependencies optional, then users who don't need it can use --no-optionalwhen installing to reduce their installation size.

A better, but far more involved solution would be to split the build toolchain into its own package and let users who want to do a custom build install that instead.

hubgit commented 5 years ago

I noticed that adding autotrack to a project's dependencies in order to import the plugins also adds various large packages such as rollup and google-closure-compiler-js. It would be good not to have these installed by default.