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 🙏

© 2025 – Pkg Stats / Ryan Hefner

static-source-data

v1.0.0

Published

<h1 align="center">Static Source Data</h1> <p align="center"> <em>framework-agnostic fetch data from API service at build time (without emit any new file) built with webpack</em> </p>

Downloads

10

Readme

About Static Source Data

The goal of this module is we want to show data in page from API Servie (e.g. Landing Page, About us), we don't want to fetch data in run time (using fetch or axios) because that make user waiting for loading data. It's ok for often chagning data to use fetch at run time but for rarely changing data, it might be better in some case if we can fetch data at build time.

Why don't we hardcode content?

We want to use data from API service because we might use CMS for non-technical person to update data (headless cms is good for this) and client fetch updated data via API service.

Who's suiable for this module

  • You want to show data which rarely updated in page (e.g. Landing Page, About us) and don't want to fetch at run time.
  • You don't want to hardcode content in html because it takes time due to require collaboration of developer and non-technical person for updating content.
  • You want to implement CMS or use headless CMS service for non-technical person update content. That ways, client need to fetch data via API servie somehow.
  • You don't want to keep track content file in your workspace.

Installation

    yarn add static-source-data // or npm install static-source-data

Usage

We created webpack plugin for fetching data at build time and generate file which hidden from your workspace (it's located in this module's folder).

We also create function for retrieve data called query(key).

const StaticSourceData = require("static-source-data");

module.exports = {
    plugins: [
        ...
        // 
        new StaticSourceData({
            landingPage: "https://demoservice.com/landing-page",
            aboutUs: {
                url: "https://demoservice.com/about-us",
                method: "POST",
                // we pass options to node-fetch module, so avilable options you can see in node-fetch documentation.
            }
        })
    ]
}

You can use query(key) to get data for showing in your App.

import React from "react";
import query from "static-source-data/query";

function LandingPage() {
  // query function accept `key` parameter which it's propery name of options object which you provided in the plugin
  const data = query("landingPage");

  console.log(data);
  // data log here is API service response (in this case, query function provided parameter with "landingPage" so data will be response of API service at https://demoservice.com/landing-page )

  // For example,
  // {
  //   title: "Our good website"
  //   description: "Good website require good responsibility"
  // }
  //

  return (
    <div className="App">
      <header className="App-header">
        <h1>{data.title}</h1>
        <p>{data.description}</p>
      </header>
    </div>
  );
}

export default LandingPage;
    

create-react-app

You can use react-app-rewired for modification of the webpack configuration.

const StaticSourceData = require('static-source-data');
const path = require('path');

module.exports = (config, env) => {
    config.plugins = config.plugins.concat([
        new StaticSourceData({
            landingPage: "https://demoservice.com/landing-page",
            aboutUs: {
                url: "https://demoservice.com/about-us",
                method: "POST",
            }
        }),
    ]);

    return config;
};