Skip to content

Commit 3583235

Browse files
initial commit
0 parents  commit 3583235

38 files changed

+7328
-0
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONTENTFUL_SPACE=XXXXXXXXXX
2+
CONTENTFUL_ACCESS_TOKEN=XXXXXXXXXX
3+
CONTENTFUL_STAGING_TOKEN=XXXXXXXXXX

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/node_modules/
3+
/src/node_modules/@sapper/
4+
yarn-error.log
5+
/cypress/screenshots/
6+
/__sapper__/
7+
/.vscode/
8+
.env

.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"arrowParens": "always",
3+
"semi": false,
4+
"bracketSpacing": true,
5+
"singleQuote": true,
6+
"printWidth": 130,
7+
"tabWidth": 4
8+
}

README.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# sapper-template
2+
3+
The default [Sapper](https://github.com/sveltejs/sapper) template, available for Rollup and webpack.
4+
5+
6+
## Getting started
7+
8+
9+
### Using `degit`
10+
11+
[`degit`](https://github.com/Rich-Harris/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`:
12+
13+
```bash
14+
# for Rollup
15+
npx degit "sveltejs/sapper-template#rollup" my-app
16+
# for webpack
17+
npx degit "sveltejs/sapper-template#webpack" my-app
18+
```
19+
20+
21+
### Using GitHub templates
22+
23+
Alternatively, you can use GitHub's template feature with the [sapper-template-rollup](https://github.com/sveltejs/sapper-template-rollup) or [sapper-template-webpack](https://github.com/sveltejs/sapper-template-webpack) repositories.
24+
25+
26+
### Running the project
27+
28+
However you get the code, you can install dependencies and run the project in development mode with:
29+
30+
```bash
31+
cd my-app
32+
npm install # or yarn
33+
npm run dev
34+
```
35+
36+
Open up [localhost:3000](http://localhost:3000) and start clicking around.
37+
38+
Consult [sapper.svelte.dev](https://sapper.svelte.dev) for help getting started.
39+
40+
41+
## Structure
42+
43+
Sapper expects to find two directories in the root of your project — `src` and `static`.
44+
45+
46+
### src
47+
48+
The [src](src) directory contains the entry points for your app — `client.js`, `server.js` and (optionally) a `service-worker.js` — along with a `template.html` file and a `routes` directory.
49+
50+
51+
#### src/routes
52+
53+
This is the heart of your Sapper app. There are two kinds of routes — *pages*, and *server routes*.
54+
55+
**Pages** are Svelte components written in `.svelte` files. When a user first visits the application, they will be served a server-rendered version of the route in question, plus some JavaScript that 'hydrates' the page and initialises a client-side router. From that point forward, navigating to other pages is handled entirely on the client for a fast, app-like feel. (Sapper will preload and cache the code for these subsequent pages, so that navigation is instantaneous.)
56+
57+
**Server routes** are modules written in `.js` files, that export functions corresponding to HTTP methods. Each function receives Express `request` and `response` objects as arguments, plus a `next` function. This is useful for creating a JSON API, for example.
58+
59+
There are three simple rules for naming the files that define your routes:
60+
61+
* A file called `src/routes/about.svelte` corresponds to the `/about` route. A file called `src/routes/blog/[slug].svelte` corresponds to the `/blog/:slug` route, in which case `params.slug` is available to the route
62+
* The file `src/routes/index.svelte` (or `src/routes/index.js`) corresponds to the root of your app. `src/routes/about/index.svelte` is treated the same as `src/routes/about.svelte`.
63+
* Files and directories with a leading underscore do *not* create routes. This allows you to colocate helper modules and components with the routes that depend on them — for example you could have a file called `src/routes/_helpers/datetime.js` and it would *not* create a `/_helpers/datetime` route
64+
65+
66+
### static
67+
68+
The [static](static) directory contains any static assets that should be available. These are served using [sirv](https://github.com/lukeed/sirv).
69+
70+
In your [service-worker.js](src/service-worker.js) file, you can import these as `files` from the generated manifest...
71+
72+
```js
73+
import { files } from '@sapper/service-worker';
74+
```
75+
76+
...so that you can cache them (though you can choose not to, for example if you don't want to cache very large files).
77+
78+
79+
## Bundler config
80+
81+
Sapper uses Rollup or webpack to provide code-splitting and dynamic imports, as well as compiling your Svelte components. With webpack, it also provides hot module reloading. As long as you don't do anything daft, you can edit the configuration files to add whatever plugins you'd like.
82+
83+
84+
## Production mode and deployment
85+
86+
To start a production version of your app, run `npm run build && npm start`. This will disable live reloading, and activate the appropriate bundler plugins.
87+
88+
You can deploy your application to any environment that supports Node 8 or above. As an example, to deploy to [Now](https://zeit.co/now), run these commands:
89+
90+
```bash
91+
npm install -g now
92+
now
93+
```
94+
95+
96+
## Using external components
97+
98+
When using Svelte components installed from npm, such as [@sveltejs/svelte-virtual-list](https://github.com/sveltejs/svelte-virtual-list), Svelte needs the original component source (rather than any precompiled JavaScript that ships with the component). This allows the component to be rendered server-side, and also keeps your client-side app smaller.
99+
100+
Because of that, it's essential that the bundler doesn't treat the package as an *external dependency*. You can either modify the `external` option under `server` in [rollup.config.js](rollup.config.js) or the `externals` option in [webpack.config.js](webpack.config.js), or simply install the package to `devDependencies` rather than `dependencies`, which will cause it to get bundled (and therefore compiled) with your app:
101+
102+
```bash
103+
npm install -D @sveltejs/svelte-virtual-list
104+
```
105+
106+
107+
## Bugs and feedback
108+
109+
Sapper is in early development, and may have the odd rough edge here and there. Please be vocal over on the [Sapper issue tracker](https://github.com/sveltejs/sapper/issues).

0 commit comments

Comments
 (0)