Skip to content

Commit

Permalink
copy sapper example from vercel/vercel (#1030)
Browse files Browse the repository at this point in the history
Co-authored-by: Trek Glowacki <trek.glowacki@gmail.com>
  • Loading branch information
erikareads and trek authored Jan 13, 2025
1 parent 873a431 commit 488603d
Show file tree
Hide file tree
Showing 33 changed files with 3,834 additions and 0 deletions.
10 changes: 10 additions & 0 deletions framework-boilerplates/sapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
/node_modules/
/src/node_modules/@sapper/
yarn-error.log
/cypress/screenshots/
/__sapper__/
.env
.env.build

.vercel
1 change: 1 addition & 0 deletions framework-boilerplates/sapper/.vercelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
README.md
21 changes: 21 additions & 0 deletions framework-boilerplates/sapper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Sapper Example

This directory is a brief example of a [Sapper](https://sapper.svelte.dev/) app that can be deployed to Vercel with zero configuration.

## Deploy Your Own

Deploy your own Sapper project with Vercel.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/framework-boilerplates/sapper&template=sapper)

_Live Example: https://sapper-template.vercel.app_

### How We Created This Example

To get started with Sapper deployed with Vercel, you can use [degit](https://github.com/Rich-Harris/degit) to initialize the project:

```shell
$ npx degit "sveltejs/sapper-template#webpack" my-sapper-app
```

> The only change made is to change the build script in `package.json` to be `"sapper export"`.
18 changes: 18 additions & 0 deletions framework-boilerplates/sapper/appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "{build}"

shallow_clone: true

init:
- git config --global core.autocrlf false

build: off

environment:
matrix:
# node.js
- nodejs_version: stable

install:
- ps: Install-Product node $env:nodejs_version
- npm install cypress
- npm install
4 changes: 4 additions & 0 deletions framework-boilerplates/sapper/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:3000",
"video": false
}
5 changes: 5 additions & 0 deletions framework-boilerplates/sapper/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
23 changes: 23 additions & 0 deletions framework-boilerplates/sapper/cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('Sapper template app', () => {
beforeEach(() => {
cy.visit('/');
});

it('has the correct <h1>', () => {
cy.contains('h1', 'Great success!');
});

it('navigates to /about', () => {
cy.get('nav a')
.contains('about')
.click();
cy.url().should('include', '/about');
});

it('navigates to /blog', () => {
cy.get('nav a')
.contains('blog')
.click();
cy.url().should('include', '/blog');
});
});
17 changes: 17 additions & 0 deletions framework-boilerplates/sapper/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
25 changes: 25 additions & 0 deletions framework-boilerplates/sapper/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions framework-boilerplates/sapper/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
27 changes: 27 additions & 0 deletions framework-boilerplates/sapper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "sapper",
"private": true,
"scripts": {
"start": "sapper dev",
"dev": "sapper dev --port $PORT",
"build": "sapper export",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test": "run-p --race dev cy:run"
},
"engines": {
"node": "16.x"
},
"dependencies": {
"compression": "^1.7.1",
"polka": "next",
"sirv": "^0.4.0"
},
"devDependencies": {
"npm-run-all": "^4.1.5",
"sapper": "^0.27.0",
"svelte": "^3.0.0",
"svelte-loader": "^2.9.0",
"webpack": "^4.7.0"
}
}
5 changes: 5 additions & 0 deletions framework-boilerplates/sapper/src/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as sapper from '@sapper/app';

sapper.start({
target: document.querySelector('#sapper'),
});
60 changes: 60 additions & 0 deletions framework-boilerplates/sapper/src/components/Nav.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script>
export let segment;
</script>

<style>
nav {
border-bottom: 1px solid rgba(255,62,0,0.1);
font-weight: 300;
padding: 0 1em;
}
ul {
margin: 0;
padding: 0;
}
/* clearfix */
ul::after {
content: '';
display: block;
clear: both;
}
li {
display: block;
float: left;
}
.selected {
position: relative;
display: inline-block;
}
.selected::after {
position: absolute;
content: '';
width: calc(100% - 1em);
height: 2px;
background-color: rgb(255,62,0);
display: block;
bottom: -1px;
}
a {
text-decoration: none;
padding: 1em 0.5em;
display: block;
}
</style>

<nav>
<ul>
<li><a class='{segment === undefined ? "selected" : ""}' href='.'>home</a></li>
<li><a class='{segment === "about" ? "selected" : ""}' href='about'>about</a></li>

<!-- for the blog link, we're using rel=prefetch so that Sapper prefetches
the blog data when we hover over the link or tap it on a touchscreen -->
<li><a rel=prefetch class='{segment === "blog" ? "selected" : ""}' href='blog'>blog</a></li>
</ul>
</nav>
40 changes: 40 additions & 0 deletions framework-boilerplates/sapper/src/routes/_error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script>
export let status;
export let error;
const dev = process.env.NODE_ENV === 'development';
</script>

<style>
h1, p {
margin: 0 auto;
}
h1 {
font-size: 2.8em;
font-weight: 700;
margin: 0 0 0.5em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>

<svelte:head>
<title>{status}</title>
</svelte:head>

<h1>{status}</h1>

<p>{error.message}</p>

{#if dev && error.stack}
<pre>{error.stack}</pre>
{/if}
22 changes: 22 additions & 0 deletions framework-boilerplates/sapper/src/routes/_layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script>
import Nav from '../components/Nav.svelte';
export let segment;
</script>

<style>
main {
position: relative;
max-width: 56em;
background-color: white;
padding: 2em;
margin: 0 auto;
box-sizing: border-box;
}
</style>

<Nav {segment}/>

<main>
<slot></slot>
</main>
7 changes: 7 additions & 0 deletions framework-boilerplates/sapper/src/routes/about.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<svelte:head>
<title>About</title>
</svelte:head>

<h1>About this site</h1>

<p>This is the 'about' page. There's not much here.</p>
28 changes: 28 additions & 0 deletions framework-boilerplates/sapper/src/routes/blog/[slug].json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import posts from './_posts.js';

const lookup = new Map();
posts.forEach(post => {
lookup.set(post.slug, JSON.stringify(post));
});

export function get(req, res, next) {
// the `slug` parameter is available because
// this file is called [slug].json.js
const { slug } = req.params;

if (lookup.has(slug)) {
res.writeHead(200, {
'Content-Type': 'application/json'
});

res.end(lookup.get(slug));
} else {
res.writeHead(404, {
'Content-Type': 'application/json'
});

res.end(JSON.stringify({
message: `Not found`
}));
}
}
Loading

0 comments on commit 488603d

Please sign in to comment.