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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@serverless-stack/static-site-env

v1.18.4

Published

A simple CLI that allows your static site to load the environment variables from your SST app.

Downloads

3,900

Readme

@serverless-stack/static-site-env npm

A simple CLI (@serverless-stack/static-site-env that allows your static site or Next.js app to load the environment variables from your SST app. This means that you won't have to hard code the config from your backend. Supports React.js, Next.js, and Svelte.

Installation

Run the following in the root of your static site or Next.js app.

# With npm
npm install @serverless-stack/static-site-env --save-dev
# Or with Yarn
yarn add @serverless-stack/static-site-env --dev

Usage

Once installed, tweak the start command in your package.json scripts.

Note that, you need to have sst start running for this to work.

React.js

"scripts": {
  "start": "sst-env -- react-scripts start",
},

Start your local dev environment as usual.

npm run start

Next.js

"scripts": {
  "dev": "sst-env -- next dev",
},

And run.

npm run dev

Svelte

"scripts": {
  "dev": "sst-env -- vite",
},

And run.

npm run dev

Options

--path

A relative path to the directory containing the sst.json file.

Note that, the sst-env CLI will traverse up the directories to look for the root of your SST app. If the static site or Next.js app is located outside the SST app folder, for example:

/
  backend/
    sst.json
  frontend/
    package.json

Pass in --path to specify the relative path of the SST app.

"scripts": {
  "start": "sst-env --path ../backend -- react-scripts start",
},

How it works

Here's what's going on behind the scenes.

  1. The sst start command generates a file with the values specified by StaticSite, ReactStaticSite, ViteStaticSite, or NextjsSite construct's environment prop.
  2. The sst-env CLI will traverse up the directories to look for the root of your SST app. If the static site or Next.js app is located outside the SST app folder, pass in --path to specify the relative path of the SST app.
  3. It'll then find the file that's generated in step 1.
  4. It'll load these as environment variables before running the start command.