-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy sapper example from vercel/vercel (#1030)
Co-authored-by: Trek Glowacki <trek.glowacki@gmail.com>
- Loading branch information
1 parent
873a431
commit 488603d
Showing
33 changed files
with
3,834 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"baseUrl": "http://localhost:3000", | ||
"video": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { ... }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
framework-boilerplates/sapper/src/routes/blog/[slug].json.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
})); | ||
} | ||
} |
Oops, something went wrong.