Skip to content

Manage environment variables in a Sapper application

Notifications You must be signed in to change notification settings

fakiolinho/sapper-env-vars

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sapper-template

The default Sapper template, available for Rollup and webpack.

Getting started

Using degit

degit is a scaffolding tool that lets you create a directory from a branch in a repository. Use either the rollup or webpack branch in sapper-template:

# for Rollup
npx degit "sveltejs/sapper-template#rollup" my-app
# for webpack
npx degit "sveltejs/sapper-template#webpack" my-app

Running the project

However you get the code, you can install dependencies and run the project in development mode with:

cd my-app
npm install # or yarn
npm run dev

Open up localhost:3000 and start clicking around.

Consult sapper.svelte.dev for help getting started.

Set up environment variables

  1. Create a .env file:
NEWSLETTER_API_TOKEN=XXX
  1. Include it in .gitignore so you don't commit it accidentally

  2. Install dotenv package

yarn add dotenv
  1. Bootstrap dotenv in drc/server.js file

  2. Add NEWSLETTER_API_TOKEN in session by using sapper.middleware

  3. You can check how you can access NEWSLETTER_API_TOKEN in preload function of src/routes/index.svelte page component

  4. You can check how you can access NEWSLETTER_API_TOKEN through session store across every component in src/components/Nav.svelte component

About

Manage environment variables in a Sapper application

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published