clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

Bundle size #42

Closed kilinkis closed 5 years ago

kilinkis commented 5 years ago

Hi guys,

I did a very basic integration using this API but the size of the bundle is too big, I think because of the dependencies. See the following screenshot and below it, my package.json file:

Screenshot 2019-06-19 at 14 56 10
{
  "name": "webpack-starter",
  "version": "1.0.0",
  "description": "A light foundation for your next frontend project based on webpack.",
  "scripts": {
    "build": "webpack --config webpack/webpack.config.prod.js  --colors",
    "start": "webpack-dev-server --open --config webpack/webpack.config.dev.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/wbkd/webpack-starter.git"
  },
  "keywords": [
    "webpack",
    "startkit",
    "frontend",
    "es6",
    "javascript",
    "webdev"
  ],
  "author": "webkid.io",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/wbkd/webpack-starter/issues"
  },
  "devDependencies": {
    "@babel/core": "^7.4.0",
    "@babel/plugin-proposal-class-properties": "^7.4.0",
    "@babel/plugin-syntax-dynamic-import": "^7.2.0",
    "@babel/preset-env": "^7.4.2",
    "babel-loader": "^8.0.5",
    "clean-webpack-plugin": "^2.0.2",
    "copy-webpack-plugin": "^5.0.3",
    "css-loader": "^3.0.0",
    "eslint": "^5.16.0",
    "eslint-loader": "^2.1.2",
    "file-loader": "^4.0.0",
    "html-webpack-plugin": "^4.0.0-beta.5",
    "mini-css-extract-plugin": "^0.7.0",
    "node-sass": "^4.12.0",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.1",
    "webpack": "^4.29.6",
    "webpack-bundle-analyzer": "^3.3.2",
    "webpack-cli": "^3.3.0",
    "webpack-dev-server": "^3.2.1",
    "webpack-merge": "^4.2.1"
  },
  "dependencies": {
    "@babel/polyfill": "^7.4.0",
    "clearbit": "^1.3.4",
    "core-js": "^3.0.1"
  }
}

is there anything I can do to decrease the size?

my script is just a js with this example from the docs:

var clearbit = require('clearbit')('sk_<redacted>');

clearbit.Enrichment.find({email: 'alex@clearbit.com', stream: true})
  .then(function (response) {
    var person  = response.person;
    var company = response.company;

    console.log('Name: ', person && person.name.fullName);
  })
  .catch(function (err) {
    console.error(err);
  });

I guess this is because it's meant to be used in node and not in the front end. But it can probably be optimised a little. Like it's only using three methods of lodash and still imports *

t-richards commented 5 years ago

Hi @kilinkis,

I guess this is because it's meant to be used in node and not in the front end. But it can probably be optimised a little. Like it's only using three methods of lodash and still imports *

You're correct here on both counts.

  1. This library was not designed to be used in the browser. Especially because placing your secret key in your JS bundle would expose it to everyone! This is not good.

    var clearbit = require('clearbit')('sk_<redacted>'); // Don't do this
  2. It wouldn't be a bad idea to trim down the giant lodash import and prune other unnecessary dependencies from this library.

kilinkis commented 5 years ago

You're right, for a moment I thought that was a public key.

Thanks for your answer @t-richards :) I guess you can close this issue now.