Git Product home page Git Product logo

sapp's Introduction

S&PP: Style and Prototyping Pack

S&PP is an Elm starter for quick web app prototyping. This starter uses Webpack for bundling, Basscss and Google Material Icons for UI scaffolding, Github Pages and Surge.sh for easy deployment to testing environments, and json server for faking a RESTful API implementation.

Table of Contents

Setup
Develop
Build
Deploy
Configure
Preview

Setup

Install Elm Packages

This project assumes that you have the Elm installed and thusly have access to it's executables.

elm-package install

Install External Packages

This project uses yarn for external package management. To install packages run:

yarn

Develop

In development we use Webpack Dev Server to serve our index.html. The app uses JSON Server to serve mock data from a JSON file.

Run Elm app + JSON Server (recommended)

If you wish to start the mock JSON server and the Elm app simultaneously:

yarn start

If you wish to run the client and mock server separately, use the following commands.

Elm App

To run the the Elm app:

yarn client

JSON Server

To run the JSON Server:

yarn api

Build

Staging

To build for staging run:

yarn build:staging

Production

To build for production run:

yarn build:prod

Deploy

Dependencies

You must have surge CLI and AWS CLI installed in order to deploy.

Deploy Targets

Deploy to surge.sh

The staging deployment builds with staging environment variables and deploys to surge.sh.

In package.json replace replace your-domain.surge.sh with your surge url, if you don't yet have one, run surge from the root of your project and copy the generated site url into this command.

...
"deploy:staging": "yarn build:staging; surge ./dist -d your-domain.surge.sh"
...

In the deploy:staging script replace your-domain.surge.sh with your surge domain. If you don't have a custom domain you can remove -d your-domain.surge.sh altogether.

yarn deploy:staging

Deploy to Github Pages

You can deploy a production build to Github Pages with the following command.

yarn deploy:gh-pages

If you are using a custom domain you must set the CNAME variable in the deploy deploy-gh-pages.sh script because Github overwrites this on every push.

Configure

Environment Variables are set in ./config/env.js. Using Webpack's DefinePlugin plugin we can expose these values to our Elm embed method without polluting the global scope.

...
development: {
  "API_URL": JSON.stringify("http://localhost:5000"),
  "NODE_ENV": JSON.stringify("development")
},
staging: {
  "API_URL": JSON.stringify("http://staging.api.com"),
  "NODE_ENV": JSON.stringify("staging")
},
production: {
  "API_URL": JSON.stringify("http://prod.api.com"),
  "NODE_ENV": JSON.stringify("production")
}
...

These variables can be accessed in the Elm app as flags in your ./src/index.js file:

var app = Elm.Main.embed(mountNode, {
  nodeEnv: NODE_ENV,
  apiUrl: API_URL
});

To use them in our Elm app we have to pass them to Elm's init function and construct our initial model with them. Elm's Html.programWithFlags allows us to do this.

init : Config -> ( Model, Cmd Msg )
init config =
    ( initialModel config, Cmd.none)

Preview

View the current state of the seed: S&PP Demo

sapp's People

Contributors

grantschulte avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.