npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

airtable-loader

v1.0.1

Published

Webpack loader for injecting Airtable data

Downloads

2

Readme

airtable-loader

This is a webpack loader that will load data from an Airtable table at build time using the settings provided in a .airtable file. This then "packs" in the data into the Javascript that is produced.

This can be useful for data you want to inject at build time from Airtable.

Updates

01/09/2021: The latest version of this project has been updated to work with Webpack 5 and I have not tested it on older versions. See the updated example for details: example webpack project

Install

yarn add -D airtable-loader

or

npm install --save-dev airtable-loader

The .airtable File

The .airtable file contains the settings that will be used to generate the data to pack. Referencing the file (i.e. import myData from 'mydata.airtable';) will create a Javascript object that contains the data from the Airtable table(s).

Params

| Parameter Name | Description | | ---------------------- | ----------------------------------------------------------------------------------------------------------------------- | | baseId | The Airtable base id (can be found in the API documentation for the Workspace) | | tableName | The name of the Airtable table | | maxRecords | The maximum number of records limit the Airtable API request | | includeFilterFieldName | The mapToName field (a boolean value) to filter what the data is produced | | cacheTables | Array of cacheTables that the loader will pre-fetch and cache in an effort to reduce the number of requests to Airtable | | fields | Array of field mappings from Airtable to the Javascript object that's produced |

cacheTables

| Parameter Name | Description | | -------------- | ------------------------------------------------------------------------------ | | baseId | The Airtable base id (can be found in the API documentation for the Workspace) | | tableName | The name of the Airtable table |

fields

| Parameter Name | Description | | -------------- | ------------------------------------------------------------------------------------- | | name | The exact name of the column in Airtable | | mapToName | The name that will be used in the Javascript object that's produced | | resolve | Used to resolve fields that have arrays of Airtable Ids that reference another table. |

resolve

| Parameter Name | Description | | ---------------------- | ------------------------------------------------------------------------------ | | baseId | The Airtable base id (can be found in the API documentation for the Workspace) | | tableName | The name of the Airtable table | | maxRecords | The maximum number of records limit the Airtable API request | | includeFilterFieldName | The mapToName field (a boolean value) to filter what the data is produced | | fields | Array of field mappings from Airtable to the Javascript object that's produced |

Example webpack configuration

module.exports = {
  entry: './src/index.js',
  module: {
    rules: [
      {
        test: /\.airtable/,
        loader: 'airtable-loader',
        options: {
          apiKey: 'AIRTABLE_API_KEY'
        }
      }
    ]
  }
};

Example .airtable file

The .airtable file should be in JSON format

contacts.airtable

{
  "baseId": "<TABLE BASE ID>",
  "tableName": "Contacts",
  "maxRecords": 200,
  "fields": [
    {
      "name": "Name",
      "mapToName": "name"
    },
    {
      "name": "Phone",
      "mapToName": "phone"
    }
  ]
}

Joining tables (resolving ids)

{
  "baseId": "appmtqyIlK7hZ4kwL",
  "tableName": "Contacts",
  "maxRecords": 2,
  "fields": [
    {
      "name": "Name",
      "mapToName": "name"
    },
    {
      "name": "Phone",
      "mapToName": "phone"
    },
    {
      "name": "Skills",
      "mapToName": "skills",
      "resolve": {
        "tableName": "Contacts",
        "baseId": "appmtqyIlK7hZ4kwL",
        "fields": [
          {
            "name": "Skill Name",
            "mapToName": "skillName"
          }
        ]
      }
    }
  ]
}

Caching complete tables

To save on requests to Airtable, you can have the loader retrieve the whole table and cache it. The loader will then look in the cache before making a request to Airtable for the individual record.

{
    "baseId": "appmtqyIlK7hZ4kwL",
    "tableName": "Contacts",
     "cacheTables": [
         {
             "tableName": "Contacts",
             "baseId": "appmtqyIlK7hZ4kwL"
         }
     ],
    "fields": ...
}

Use in code

import React from 'react';
import ReactDOM from 'react-dom';
import contacts from './contacts.airtable';

const Contacts = () => {
  return contacts.map((contact, i) => (
    <li key={i}>
      {contact.name}: {contact.phone}
    </li>
  ));
};

const App = () => {
  return (
    <div>
      <h1>Contacts</h1>
      <ul>
        <Contacts />
      </ul>
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('app'));

Typescript

If you are using this loader in a project writen in Typescript, you will need to create a module definition for the airtable (or what ever you name it) file type. Something like this in your @types directory:

// airtable.d.ts
declare module '*.airtable' {
  const content: any;
  export default content;
}

TODOs

  • [ ] Convert loader code to Typescript