├── .vscode ├── extensions.json └── settings.json ├── .gitignore ├── static ├── favicon.png ├── logo-192.png ├── logo-512.png ├── screenshot-1.png ├── screenshot-2.png ├── apple-touch-icon-180.png ├── main.css ├── manifest.json └── normalize.css ├── src ├── client.ts ├── routes │ ├── example.ts │ ├── _error.svelte │ ├── _layout.svelte │ └── index.svelte ├── components │ └── ExampleComponent.svelte ├── graphql │ └── index.ts ├── server.ts ├── template.html └── service-worker.ts ├── svelte.config.js ├── tsconfig.json ├── LICENSE ├── .eslintrc.json ├── package.json ├── rollup.config.js └── README.md /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "svelte.svelte-vscode" 4 | ] 5 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ._* 2 | .DS_Store 3 | /.history/ 4 | /node_modules/ 5 | __sapper__/ 6 | /src/node_modules/@sapper/ 7 | -------------------------------------------------------------------------------- /static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babichjacob/sapper-typescript-graphql-template/HEAD/static/favicon.png -------------------------------------------------------------------------------- /static/logo-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babichjacob/sapper-typescript-graphql-template/HEAD/static/logo-192.png -------------------------------------------------------------------------------- /static/logo-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babichjacob/sapper-typescript-graphql-template/HEAD/static/logo-512.png -------------------------------------------------------------------------------- /static/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babichjacob/sapper-typescript-graphql-template/HEAD/static/screenshot-1.png -------------------------------------------------------------------------------- /static/screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babichjacob/sapper-typescript-graphql-template/HEAD/static/screenshot-2.png -------------------------------------------------------------------------------- /static/apple-touch-icon-180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babichjacob/sapper-typescript-graphql-template/HEAD/static/apple-touch-icon-180.png -------------------------------------------------------------------------------- /src/client.ts: -------------------------------------------------------------------------------- 1 | import * as sapper from "@sapper/app"; // eslint-disable-line import/no-unresolved 2 | 3 | sapper.start({ 4 | target: document.querySelector("#sapper"), 5 | }); 6 | -------------------------------------------------------------------------------- /src/routes/example.ts: -------------------------------------------------------------------------------- 1 | import type { Request as ExpressRequest, Response as ExpressResponse } from "express"; 2 | 3 | export const get = async (req: ExpressRequest, res: ExpressResponse): Promise => { 4 | res.end("you made a get request"); 5 | }; 6 | 7 | export const post = async (req: ExpressRequest, res: ExpressResponse): Promise => { 8 | res.end("you made a post request"); 9 | }; 10 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { 3 | "source.fixAll": true 4 | }, 5 | "[javascript]": { 6 | "editor.defaultFormatter": "dbaeumer.vscode-eslint" 7 | }, 8 | "[typescript]": { 9 | "editor.defaultFormatter": "dbaeumer.vscode-eslint" 10 | }, 11 | "eslint.format.enable": true, 12 | "eslint.lintTask.enable": true, 13 | "typescript.tsdk": "node_modules/typescript/lib", 14 | } 15 | -------------------------------------------------------------------------------- /src/components/ExampleComponent.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 22 | 23 |

{title}

24 |

{paragraph}

25 | -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | const sveltePreprocess = require("svelte-preprocess"); 2 | 3 | const createPreprocessors = ({ sourceMap }) => [ 4 | sveltePreprocess({ 5 | sourceMap, 6 | defaults: { 7 | script: "typescript", 8 | }, 9 | }), 10 | // You could have more preprocessors, like mdsvex 11 | ]; 12 | 13 | module.exports = { 14 | createPreprocessors, 15 | // Options for `svelte-check` and the VS Code extension 16 | preprocess: createPreprocessors({ sourceMap: true }), 17 | }; 18 | -------------------------------------------------------------------------------- /static/main.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; 3 | } 4 | 5 | body { 6 | display: flex; 7 | flex-direction: column; 8 | width: 100%; 9 | min-height: 100vh; 10 | line-height: 1.0; 11 | } 12 | 13 | #sapper { 14 | display: flex; 15 | flex-direction: column; 16 | flex: 1 1 0%; 17 | } 18 | -------------------------------------------------------------------------------- /src/graphql/index.ts: -------------------------------------------------------------------------------- 1 | import "reflect-metadata"; 2 | import { ApolloServer } from "apollo-server-express"; 3 | import { Query, Resolver, buildSchema } from "type-graphql"; 4 | 5 | @Resolver() 6 | class HelloWorldResolver { 7 | @Query(() => String, { description: "Example thing to query" }) 8 | async helloWorld(): Promise { 9 | return "Hello world!"; 10 | } 11 | } 12 | 13 | export const createApolloServer = async (): Promise => { 14 | const schema = await buildSchema({ resolvers: [HelloWorldResolver] }); 15 | 16 | const apolloServer = new ApolloServer({ 17 | schema, 18 | playground: true, 19 | introspection: true, 20 | }); 21 | 22 | return apolloServer; 23 | }; 24 | -------------------------------------------------------------------------------- /src/routes/_error.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 31 | 32 |
33 |

{error.message}

34 |

{status}

35 |
36 | 37 | {#if dev && error.stack} 38 |
{error.stack}
39 | {/if} 40 | -------------------------------------------------------------------------------- /src/routes/_layout.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 20 | 21 | 22 | 23 | {path ? path.charAt(0).toUpperCase() + path.slice(1) : "Index"} 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": [ 4 | "DOM", 5 | "ES2017", 6 | "WebWorker" 7 | ], 8 | "target": "es2017", 9 | "allowSyntheticDefaultImports": true, 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importsNotUsedAsValues": "error", 13 | "isolatedModules": true, 14 | "moduleResolution": "node", 15 | "sourceMap": true, 16 | "strict": true, 17 | "types": [ 18 | "svelte" 19 | ], 20 | }, 21 | "include": [ 22 | "src/**/*", 23 | "src/node_modules/**/*" 24 | ], 25 | "exclude": [ 26 | "node_modules/*", 27 | "__sapper__/*", 28 | "static/*" 29 | ], 30 | } 31 | -------------------------------------------------------------------------------- /src/server.ts: -------------------------------------------------------------------------------- 1 | import * as sapper from "@sapper/server"; // eslint-disable-line import/no-unresolved 2 | import compression from "compression"; 3 | import express, { Express } from "express"; 4 | import sirv from "sirv"; 5 | import { createApolloServer } from "./graphql"; 6 | 7 | const PORT = process.env.PORT; // eslint-disable-line prefer-destructuring 8 | const mode = process.env.NODE_ENV; 9 | const dev = mode === "development"; 10 | 11 | const createSapperAndApolloServer = async (graphqlPath: string): Promise => { 12 | const app = express(); 13 | 14 | const apolloServer = await createApolloServer(); 15 | 16 | apolloServer.applyMiddleware({ app, path: graphqlPath }); 17 | 18 | app.use( 19 | compression({ threshold: 0 }), 20 | sirv("static", { dev }), 21 | sapper.middleware(), 22 | ); 23 | 24 | return app; 25 | }; 26 | 27 | createSapperAndApolloServer("/graphql").then((app) => { 28 | app.listen(PORT, (err?: any): void => { // eslint-disable-line 29 | if (err) console.log("error", err); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /static/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "Sapper + TypeScript + GraphQL", 3 | "name": "Sapper with TypeScript and GraphQL project base", 4 | "description": "A template that includes Svelte with Sapper, TypeScript preprocessing, and a GraphQL server through TypeGraphQL", 5 | "categories": ["personalization", "productivity"], 6 | "lang": "en-US", 7 | "dir": "ltr", 8 | "icons": [ 9 | { 10 | "src": "logo-192.png", 11 | "sizes": "192x192", 12 | "type": "image/png", 13 | "purpose": "any maskable" 14 | }, 15 | { 16 | "src": "logo-512.png", 17 | "sizes": "512x512", 18 | "type": "image/png", 19 | "purpose": "any maskable" 20 | } 21 | ], 22 | "start_url": "/", 23 | "display": "minimal-ui", 24 | "background_color": "#FFFFFF", 25 | "theme_color": "#3F83F8", 26 | "screenshots": [ 27 | { 28 | "src": "screenshot-1.png", 29 | "sizes": "1280x720", 30 | "type": "image/png" 31 | }, 32 | { 33 | "src": "screenshot-2.png", 34 | "sizes": "1280x720", 35 | "type": "image/png" 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /src/template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %sapper.base% 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | %sapper.styles% 22 | 23 | 25 | %sapper.head% 26 | 27 | 28 | 29 |
30 | %sapper.html% 31 |
32 | 33 | %sapper.scripts% 34 | 35 | 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Jacob Babich 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/routes/index.svelte: -------------------------------------------------------------------------------- 1 | 4 | 5 | 39 | 40 | 46 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended", 4 | "airbnb-base" 5 | ], 6 | "parserOptions": { 7 | "ecmaVersion": 11, 8 | "sourceType": "module", 9 | "project": "./tsconfig.json" 10 | }, 11 | "env": { 12 | "node": true, 13 | "browser": true, 14 | "es2020": true 15 | }, 16 | "rules": { 17 | "class-methods-use-this": "off", 18 | "import/extensions": [ 19 | "error", 20 | "ignorePackages", 21 | { 22 | "js": "never", 23 | "ts": "never" 24 | } 25 | ], 26 | "import/prefer-default-export": "off", 27 | "import/no-extraneous-dependencies": "off", 28 | "indent": [ 29 | "error", 30 | "tab" 31 | ], 32 | "no-console": "off", 33 | "no-tabs": [ 34 | "error", 35 | { 36 | "allowIndentationTabs": true 37 | } 38 | ], 39 | "no-unused-vars": [ 40 | "error", 41 | { 42 | "argsIgnorePattern": "^_", 43 | "varsIgnorePattern": "^_" 44 | } 45 | ], 46 | "quotes": [ 47 | "error", 48 | "double" 49 | ] 50 | }, 51 | "overrides": [ 52 | { 53 | "files": [ 54 | "*.ts" 55 | ], 56 | "parser": "@typescript-eslint/parser", 57 | "extends": [ 58 | "plugin:import/typescript", 59 | "plugin:@typescript-eslint/recommended" 60 | ], 61 | "plugins": [ 62 | "@typescript-eslint" 63 | ], 64 | "rules": { 65 | "@typescript-eslint/ban-ts-comment": "off" 66 | } 67 | }, 68 | { 69 | "files": [ 70 | "*.svelte" 71 | ], 72 | "plugins": [ 73 | "svelte3" 74 | ], 75 | "processor": "svelte3/svelte3", 76 | "rules": { 77 | "import/first": "off", 78 | "import/no-duplicates": "off", 79 | "import/no-mutable-exports": "off", 80 | "import/no-mutable-unresolved": "off", 81 | "no-undef": "off", 82 | "no-unused-vars": "off" 83 | } 84 | } 85 | ] 86 | } 87 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sapper-typescript-graphql-template", 3 | "description": "A template that includes Svelte with Sapper, TypeScript preprocessing, and a GraphQL server through TypeGraphQL", 4 | "keywords": [ 5 | "sapper", 6 | "typegraphql", 7 | "typescript", 8 | "eslint", 9 | "svelte", 10 | "apollo-server", 11 | "graphql" 12 | ], 13 | "homepage": "https://github.com/babichjacob/sapper-typescript-graphql-template", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/babichjacob/sapper-typescript-graphql-template.git" 17 | }, 18 | "license": "MIT", 19 | "version": "2020.12.12", 20 | "scripts": { 21 | "eslint": "eslint", 22 | "eslint:fix": "eslint --fix ./*.js ./src/*.ts ./src/components/**/*.svelte ./src/graphql/**/*.ts ./src/routes/**/*.svelte ./src/routes/**/*.ts", 23 | "validate": "svelte-check --ignore src/node_modules/@sapper", 24 | "validate:dev": "svelte-check --ignore src/node_modules/@sapper --watch", 25 | "sapper:dev": "sapper dev", 26 | "sapper:build": "cross-env NODE_ENV=production sapper build --legacy", 27 | "sapper:export": "cross-env NODE_ENV=production sapper export --legacy", 28 | "dev": "run-p validate:dev sapper:dev", 29 | "prod": "run-s sapper:build validate", 30 | "start": "node __sapper__/build", 31 | "export": "run-s sapper:export validate" 32 | }, 33 | "dependencies": { 34 | "compression": "^1.7.4", 35 | "express": "^4.17.1", 36 | "node-fetch": "^2.6.1", 37 | "sirv": "^1.0.10" 38 | }, 39 | "devDependencies": { 40 | "@babel/core": "^7.12.10", 41 | "@babel/plugin-syntax-dynamic-import": "^7.8.3", 42 | "@babel/plugin-transform-runtime": "^7.12.10", 43 | "@babel/preset-env": "^7.12.10", 44 | "@babel/runtime": "^7.12.5", 45 | "@rollup/plugin-babel": "^5.2.2", 46 | "@rollup/plugin-commonjs": "^17.0.0", 47 | "@rollup/plugin-json": "^4.1.0", 48 | "@rollup/plugin-node-resolve": "^10.0.0", 49 | "@rollup/plugin-replace": "^2.3.4", 50 | "@rollup/plugin-typescript": "^8.0.0", 51 | "@types/compression": "^1.7.0", 52 | "@types/express": "^4.17.9", 53 | "@types/node-fetch": "^2.5.7", 54 | "@typescript-eslint/eslint-plugin": "^4.9.1", 55 | "@typescript-eslint/parser": "^4.9.1", 56 | "apollo-server-express": "^2.19.0", 57 | "bufferutil": "^4.0.2", 58 | "class-validator": "^0.12.2", 59 | "cross-env": "^7.0.3", 60 | "eslint": "^7.15.0", 61 | "eslint-config-airbnb-base": "^14.2.1", 62 | "eslint-plugin-import": "^2.22.1", 63 | "eslint-plugin-svelte3": "^2.7.3", 64 | "graphql": "^15.4.0", 65 | "npm-run-all": "^4.1.5", 66 | "reflect-metadata": "^0.1.13", 67 | "rollup": "^2.34.2", 68 | "rollup-plugin-svelte": "^7.0.0", 69 | "rollup-plugin-terser": "^7.0.2", 70 | "sapper": "^0.28.10", 71 | "svelte": "^3.31.0", 72 | "svelte-check": "^1.1.22", 73 | "svelte-preprocess": "^4.6.1", 74 | "tslib": "^2.0.3", 75 | "type-graphql": "^1.1.1", 76 | "typescript": "^4.1.3", 77 | "utf-8-validate": "^5.0.3" 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/service-worker.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-restricted-globals,@typescript-eslint/no-explicit-any */ 2 | import { timestamp, files, shell } from "@sapper/service-worker"; 3 | 4 | const ASSETS = `cache${timestamp}`; 5 | 6 | // `shell` is an array of all the files generated by the bundler, 7 | // `files` is an array of everything in the `static` directory 8 | const toCache = (shell as string[]).concat(files as string[]); 9 | const cached = new Set(toCache); 10 | 11 | self.addEventListener("install", (event: EventType) => { 12 | event.waitUntil( 13 | caches 14 | .open(ASSETS) 15 | .then((cache) => cache.addAll(toCache)) 16 | .then(() => { 17 | (self as any as ServiceWorkerGlobalScope).skipWaiting(); 18 | }), 19 | ); 20 | }); 21 | 22 | self.addEventListener("activate", (event: EventType) => { 23 | event.waitUntil( 24 | caches.keys().then(async (keys) => { 25 | // delete old caches 26 | for (const key of keys) { // eslint-disable-line no-restricted-syntax 27 | if (key !== ASSETS) await caches.delete(key); // eslint-disable-line no-await-in-loop 28 | } 29 | 30 | (self as any as {clients: Clients}).clients.claim(); 31 | }), 32 | ); 33 | }); 34 | 35 | self.addEventListener("fetch", (event: EventType) => { 36 | if (event.request.method !== "GET" || event.request.headers.has("range")) return; 37 | 38 | const url = new URL(event.request.url); 39 | 40 | // don't try to handle e.g. data: URIs 41 | if (!url.protocol.startsWith("http")) return; 42 | 43 | // ignore dev server requests 44 | if (url.hostname === self.location.hostname && url.port !== self.location.port) return; 45 | 46 | // always serve static files and bundler-generated assets from cache 47 | if (url.host === self.location.host && cached.has(url.pathname)) { 48 | event.respondWith(caches.match(event.request) as Promise); 49 | return; 50 | } 51 | 52 | // for pages, you might want to serve a shell `service-worker-index.html` file, 53 | // which Sapper has generated for you. It's not right for every 54 | // app, but if it's right for yours then uncomment this section 55 | /* 56 | if (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) { 57 | event.respondWith(caches.match('/service-worker-index.html')); 58 | return; 59 | } 60 | */ 61 | 62 | if (event.request.cache === "only-if-cached") return; 63 | 64 | // for everything else, try the network first, falling back to 65 | // cache if the user is offline. (If the pages never change, you 66 | // might prefer a cache-first approach to a network-first one.) 67 | event.respondWith( 68 | caches 69 | .open(`offline${timestamp}`) 70 | .then(async (cache) => { 71 | try { 72 | const response = await fetch(event.request); 73 | cache.put(event.request, response.clone()); 74 | return response; 75 | } catch (err) { 76 | const response = await cache.match(event.request); 77 | if (response) return response; 78 | 79 | throw err; 80 | } 81 | }), 82 | ); 83 | }); 84 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from "@rollup/plugin-node-resolve"; 2 | import replace from "@rollup/plugin-replace"; 3 | import commonjs from "@rollup/plugin-commonjs"; 4 | import json from "@rollup/plugin-json"; 5 | import typescript from "@rollup/plugin-typescript"; 6 | import svelte from "rollup-plugin-svelte"; 7 | import babel from "@rollup/plugin-babel"; 8 | import { terser } from "rollup-plugin-terser"; 9 | import config from "sapper/config/rollup"; 10 | import pkg from "./package.json"; 11 | 12 | const { createPreprocessors } = require("./svelte.config.js"); 13 | 14 | const mode = process.env.NODE_ENV; 15 | const dev = mode === "development"; 16 | const sourcemap = dev ? "inline" : false; 17 | const legacy = !!process.env.SAPPER_LEGACY_BUILD; 18 | 19 | const preprocess = createPreprocessors({ sourceMap: !!sourcemap }); 20 | 21 | const warningIsIgnored = (warning) => warning.message.includes( 22 | "Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification", 23 | ) || warning.message.includes("Circular dependency: node_modules"); 24 | 25 | // Workaround for https://github.com/sveltejs/sapper/issues/1266 26 | const onwarn = (warning, _onwarn) => (warning.code === "CIRCULAR_DEPENDENCY" && /[/\\]@sapper[/\\]/.test(warning.message)) || warningIsIgnored(warning) || console.warn(warning.toString()); 27 | 28 | export default { 29 | client: { 30 | input: config.client.input().replace(/\.js$/, ".ts"), 31 | output: { ...config.client.output(), sourcemap }, 32 | plugins: [ 33 | replace({ 34 | "process.browser": true, 35 | "process.env.NODE_ENV": JSON.stringify(mode), 36 | }), 37 | svelte({ 38 | compilerOptions: { 39 | dev, 40 | hydratable: true, 41 | }, 42 | emitCss: true, 43 | preprocess, 44 | }), 45 | resolve({ 46 | browser: true, 47 | dedupe: ["svelte"], 48 | }), 49 | commonjs({ 50 | sourceMap: !!sourcemap, 51 | }), 52 | typescript({ 53 | noEmitOnError: !dev, 54 | sourceMap: !!sourcemap, 55 | }), 56 | json(), 57 | 58 | legacy && babel({ 59 | extensions: [".js", ".mjs", ".html", ".svelte"], 60 | babelHelpers: "runtime", 61 | exclude: ["node_modules/@babel/**"], 62 | presets: [ 63 | ["@babel/preset-env", { 64 | targets: "> 0.25%, not dead", 65 | }], 66 | ], 67 | plugins: [ 68 | "@babel/plugin-syntax-dynamic-import", 69 | ["@babel/plugin-transform-runtime", { 70 | useESModules: true, 71 | }], 72 | ], 73 | }), 74 | 75 | !dev && terser({ 76 | module: true, 77 | }), 78 | ], 79 | 80 | preserveEntrySignatures: false, 81 | onwarn, 82 | }, 83 | 84 | server: { 85 | input: { server: config.server.input().server.replace(/\.js$/, ".ts") }, 86 | output: { ...config.server.output(), sourcemap }, 87 | plugins: [ 88 | replace({ 89 | "process.browser": false, 90 | "process.env.NODE_ENV": JSON.stringify(mode), 91 | "module.require": "require", 92 | }), 93 | svelte({ 94 | compilerOptions: { 95 | dev, 96 | generate: "ssr", 97 | }, 98 | preprocess, 99 | }), 100 | resolve({ 101 | dedupe: ["svelte"], 102 | }), 103 | commonjs({ 104 | sourceMap: !!sourcemap, 105 | }), 106 | typescript({ 107 | noEmitOnError: !dev, 108 | sourceMap: !!sourcemap, 109 | }), 110 | json(), 111 | ], 112 | external: Object.keys(pkg.dependencies).concat( 113 | require("module").builtinModules || Object.keys(process.binding("natives")), // eslint-disable-line global-require 114 | ), 115 | 116 | preserveEntrySignatures: "strict", 117 | onwarn, 118 | }, 119 | 120 | serviceworker: { 121 | input: config.serviceworker.input().replace(/\.js$/, ".ts"), 122 | output: { ...config.serviceworker.output(), sourcemap }, 123 | plugins: [ 124 | resolve(), 125 | replace({ 126 | "process.browser": true, 127 | "process.env.NODE_ENV": JSON.stringify(mode), 128 | }), 129 | commonjs({ 130 | sourceMap: !!sourcemap, 131 | }), 132 | typescript({ 133 | noEmitOnError: !dev, 134 | sourceMap: !!sourcemap, 135 | }), 136 | !dev && terser(), 137 | ], 138 | 139 | preserveEntrySignatures: false, 140 | onwarn, 141 | }, 142 | }; 143 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

🌐 Sapper with TypeScript and GraphQL project base

2 | 3 | ## ❓ What is this? 4 | 5 | This is an extension to the [official Sapper Rollup template](https://github.com/sveltejs/sapper-template-rollup) with TypeScript preprocessing and a GraphQL server through TypeGraphQL (Apollo Server). 6 | 7 | - [Sapper for Svelte](https://sapper.svelte.dev/) 8 | - [Official VS Code Plugin](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) 9 | - [TypeScript](https://www.typescriptlang.org/) 10 | - [TypeGraphQL](https://typegraphql.com/) 11 | - Inside Svelte components, thanks to [`svelte-preprocess`](https://github.com/kaisermann/svelte-preprocess) 12 | - [Progressive Web App (PWA)](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps) best practices set up 13 | - [`manifest.json`](https://developer.mozilla.org/en-US/docs/Web/Manifest)'s most important fields filled out 14 | - High [Lighthouse](https://developers.google.com/web/tools/lighthouse) audit score 15 | - [ESLint](https://eslint.org/) 16 | - [VS Code Plugin](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) 17 | - `eslint:fix` package script 18 | 19 | If you're looking for something with much, much more bundled in, check out [my opinionated project base](https://github.com/babichjacob/sapper-firebase-typescript-graphql-tailwindcss-actions-template). 20 | 21 | ## 🧭 Project Status 22 | **This project base will continue to be maintained** [until SvelteKit is ready](https://svelte.dev/blog/whats-the-deal-with-sveltekit). 23 | 24 | Once you are prepared to migrate, check out the [Svelte Adders](https://github.com/babichjacob/svelte-adders) project for information about how to recreate this project base's functionality. You should specifically look at [svelte-add-graphql](https://github.com/babichjacob/svelte-add-graphql). 25 | 26 | **Read on to use this project base today:** 27 | 28 | ## 📋 Copy 29 | 30 | Choose either to clone or fork depending on your preference. 31 | 32 | ### 🐑 Clone 33 | 34 | ```sh 35 | git clone https://github.com/babichjacob/sapper-typescript-graphql-template 36 | ``` 37 | 38 | ### 🍴 Fork 39 | 40 | Click the `Use this template` button on [this project's GitHub page](https://github.com/babichjacob/sapper-typescript-graphql-template). 41 | 42 | ### ⬇️ Install Dependencies 43 | 44 | ```sh 45 | cd sapper-typescript-graphql-template 46 | npm install # pnpm also works 47 | ``` 48 | 49 | ## 🛠 Usage 50 | 51 | ### 🧪 Development 52 | ```sh 53 | npm run dev 54 | ``` 55 | 56 | ### 🔨 Building for Production 57 | ```sh 58 | npm run prod 59 | ``` 60 | 61 | ### 📦 Exporting a Static Site 62 | Your GraphQL server will not be exported with the rest of the site. 63 | 64 | ```sh 65 | npm run export 66 | ``` 67 | 68 | ## ⚙ Configuration 69 | 70 | ### ⚡ Web app 71 | Many of the fields in `static/manifest.json` (`short_name`, `name`, `description`, `categories`, `theme_color`, and `background_color`) are filled with demonstrative values that won't match your site. Similarly, you've got to take new screenshots to replace the included `static/screenshot-1.png` and `static/screenshot-2.png` files. If you want, you can add [app shortcut definitions for "add to home screen" on Android](https://web.dev/app-shortcuts/#define-app-shortcuts-in-the-web-app-manifest). Once you change `theme_color`, update the `meta name="theme-color"` tag in `src/template.html` to match. 72 | 73 | The [Apple touch icon](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html), favicon, and `logo-` files (also all in the `static` directory) are created by placing the logo within a "safe area" centered circle that takes up 80% of the canvas's dimension. For instance, the constraining circle in `logo-512.png` is 512 × 0.80 = 409.6 ≈ 410 pixels wide and tall. 74 | 75 | ### 🗺 Source maps 76 | This project base comes with [source maps](https://blog.teamtreehouse.com/introduction-source-maps) enabled during development and disabled during production for the best compromise between performance and developer experience. You can change this behavior through the `sourcemap` variable in `rollup.config.js`. 77 | 78 | ### 🕸 Optionally removing the GraphQL server 79 | 1. Remove these lines in `src/server.ts`: 80 | 1. ```ts 81 | import { createApolloServer } from "./graphql"; 82 | ``` 83 | 2. ```ts 84 | const apolloServer = await createApolloServer(); 85 | ``` 86 | 3. ```ts 87 | apolloServer.applyMiddleware({ app, path: graphqlPath }); 88 | ``` 89 | 90 | 2. Remove the now-useless `graphqlPath` parameter to `createSapperAndApolloServer` in `src/server.ts`. This is also a good opportunity to rename the function since there is no longer an Apollo Server 91 | 92 | 3. Delete the `src/graphql` folder 93 | 94 | 4. Uninstall the `apollo-server-express`, `bufferutil`, `class-validator`, `graphql`, `reflect-metadata`, `type-graphql`, and `utf-8-validate` packages 95 | 96 | ## 😵 Help! I have a question 97 | 98 | [Create an issue](https://github.com/babichjacob/sapper-typescript-graphql-template/issues/new) and I'll try to help. 99 | 100 | ## 😡 Fix! There is something that needs improvement 101 | 102 | [Create an issue](https://github.com/babichjacob/sapper-typescript-graphql-template/issues/new) or [pull request](https://github.com/babichjacob/sapper-typescript-graphql-template/pulls) and I'll try to fix. 103 | 104 | I'm sorry, because of my skill level and the fragility of (the combination of) some of these tools, there are likely to be problems in this project. Thank you for bringing them to my attention or fixing them for me. 105 | 106 | ## 📄 License 107 | 108 | MIT 109 | 110 | --- 111 | 112 | _This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_ 113 | -------------------------------------------------------------------------------- /static/normalize.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ 2 | 3 | /* Document 4 | ========================================================================== */ 5 | 6 | /** 7 | * 1. Correct the line height in all browsers. 8 | * 2. Prevent adjustments of font size after orientation changes in iOS. 9 | */ 10 | 11 | html { 12 | line-height: 1.15; /* 1 */ 13 | -webkit-text-size-adjust: 100%; /* 2 */ 14 | } 15 | 16 | /* Sections 17 | ========================================================================== */ 18 | 19 | /** 20 | * Remove the margin in all browsers. 21 | */ 22 | 23 | body { 24 | margin: 0; 25 | } 26 | 27 | /** 28 | * Render the `main` element consistently in IE. 29 | */ 30 | 31 | main { 32 | display: block; 33 | } 34 | 35 | /** 36 | * Correct the font size and margin on `h1` elements within `section` and 37 | * `article` contexts in Chrome, Firefox, and Safari. 38 | */ 39 | 40 | h1 { 41 | font-size: 2em; 42 | margin: 0.67em 0; 43 | } 44 | 45 | /* Grouping content 46 | ========================================================================== */ 47 | 48 | /** 49 | * 1. Add the correct box sizing in Firefox. 50 | * 2. Show the overflow in Edge and IE. 51 | */ 52 | 53 | hr { 54 | box-sizing: content-box; /* 1 */ 55 | height: 0; /* 1 */ 56 | overflow: visible; /* 2 */ 57 | } 58 | 59 | /** 60 | * 1. Correct the inheritance and scaling of font size in all browsers. 61 | * 2. Correct the odd `em` font sizing in all browsers. 62 | */ 63 | 64 | pre { 65 | font-family: monospace, monospace; /* 1 */ 66 | font-size: 1em; /* 2 */ 67 | } 68 | 69 | /* Text-level semantics 70 | ========================================================================== */ 71 | 72 | /** 73 | * Remove the gray background on active links in IE 10. 74 | */ 75 | 76 | a { 77 | background-color: transparent; 78 | } 79 | 80 | /** 81 | * 1. Remove the bottom border in Chrome 57- 82 | * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. 83 | */ 84 | 85 | abbr[title] { 86 | border-bottom: none; /* 1 */ 87 | text-decoration: underline; /* 2 */ 88 | text-decoration: underline dotted; /* 2 */ 89 | } 90 | 91 | /** 92 | * Add the correct font weight in Chrome, Edge, and Safari. 93 | */ 94 | 95 | b, 96 | strong { 97 | font-weight: bolder; 98 | } 99 | 100 | /** 101 | * 1. Correct the inheritance and scaling of font size in all browsers. 102 | * 2. Correct the odd `em` font sizing in all browsers. 103 | */ 104 | 105 | code, 106 | kbd, 107 | samp { 108 | font-family: monospace, monospace; /* 1 */ 109 | font-size: 1em; /* 2 */ 110 | } 111 | 112 | /** 113 | * Add the correct font size in all browsers. 114 | */ 115 | 116 | small { 117 | font-size: 80%; 118 | } 119 | 120 | /** 121 | * Prevent `sub` and `sup` elements from affecting the line height in 122 | * all browsers. 123 | */ 124 | 125 | sub, 126 | sup { 127 | font-size: 75%; 128 | line-height: 0; 129 | position: relative; 130 | vertical-align: baseline; 131 | } 132 | 133 | sub { 134 | bottom: -0.25em; 135 | } 136 | 137 | sup { 138 | top: -0.5em; 139 | } 140 | 141 | /* Embedded content 142 | ========================================================================== */ 143 | 144 | /** 145 | * Remove the border on images inside links in IE 10. 146 | */ 147 | 148 | img { 149 | border-style: none; 150 | } 151 | 152 | /* Forms 153 | ========================================================================== */ 154 | 155 | /** 156 | * 1. Change the font styles in all browsers. 157 | * 2. Remove the margin in Firefox and Safari. 158 | */ 159 | 160 | button, 161 | input, 162 | optgroup, 163 | select, 164 | textarea { 165 | font-family: inherit; /* 1 */ 166 | font-size: 100%; /* 1 */ 167 | line-height: 1.15; /* 1 */ 168 | margin: 0; /* 2 */ 169 | } 170 | 171 | /** 172 | * Show the overflow in IE. 173 | * 1. Show the overflow in Edge. 174 | */ 175 | 176 | button, 177 | input { /* 1 */ 178 | overflow: visible; 179 | } 180 | 181 | /** 182 | * Remove the inheritance of text transform in Edge, Firefox, and IE. 183 | * 1. Remove the inheritance of text transform in Firefox. 184 | */ 185 | 186 | button, 187 | select { /* 1 */ 188 | text-transform: none; 189 | } 190 | 191 | /** 192 | * Correct the inability to style clickable types in iOS and Safari. 193 | */ 194 | 195 | button, 196 | [type="button"], 197 | [type="reset"], 198 | [type="submit"] { 199 | -webkit-appearance: button; 200 | } 201 | 202 | /** 203 | * Remove the inner border and padding in Firefox. 204 | */ 205 | 206 | button::-moz-focus-inner, 207 | [type="button"]::-moz-focus-inner, 208 | [type="reset"]::-moz-focus-inner, 209 | [type="submit"]::-moz-focus-inner { 210 | border-style: none; 211 | padding: 0; 212 | } 213 | 214 | /** 215 | * Restore the focus styles unset by the previous rule. 216 | */ 217 | 218 | button:-moz-focusring, 219 | [type="button"]:-moz-focusring, 220 | [type="reset"]:-moz-focusring, 221 | [type="submit"]:-moz-focusring { 222 | outline: 1px dotted ButtonText; 223 | } 224 | 225 | /** 226 | * Correct the padding in Firefox. 227 | */ 228 | 229 | fieldset { 230 | padding: 0.35em 0.75em 0.625em; 231 | } 232 | 233 | /** 234 | * 1. Correct the text wrapping in Edge and IE. 235 | * 2. Correct the color inheritance from `fieldset` elements in IE. 236 | * 3. Remove the padding so developers are not caught out when they zero out 237 | * `fieldset` elements in all browsers. 238 | */ 239 | 240 | legend { 241 | box-sizing: border-box; /* 1 */ 242 | color: inherit; /* 2 */ 243 | display: table; /* 1 */ 244 | max-width: 100%; /* 1 */ 245 | padding: 0; /* 3 */ 246 | white-space: normal; /* 1 */ 247 | } 248 | 249 | /** 250 | * Add the correct vertical alignment in Chrome, Firefox, and Opera. 251 | */ 252 | 253 | progress { 254 | vertical-align: baseline; 255 | } 256 | 257 | /** 258 | * Remove the default vertical scrollbar in IE 10+. 259 | */ 260 | 261 | textarea { 262 | overflow: auto; 263 | } 264 | 265 | /** 266 | * 1. Add the correct box sizing in IE 10. 267 | * 2. Remove the padding in IE 10. 268 | */ 269 | 270 | [type="checkbox"], 271 | [type="radio"] { 272 | box-sizing: border-box; /* 1 */ 273 | padding: 0; /* 2 */ 274 | } 275 | 276 | /** 277 | * Correct the cursor style of increment and decrement buttons in Chrome. 278 | */ 279 | 280 | [type="number"]::-webkit-inner-spin-button, 281 | [type="number"]::-webkit-outer-spin-button { 282 | height: auto; 283 | } 284 | 285 | /** 286 | * 1. Correct the odd appearance in Chrome and Safari. 287 | * 2. Correct the outline style in Safari. 288 | */ 289 | 290 | [type="search"] { 291 | -webkit-appearance: textfield; /* 1 */ 292 | outline-offset: -2px; /* 2 */ 293 | } 294 | 295 | /** 296 | * Remove the inner padding in Chrome and Safari on macOS. 297 | */ 298 | 299 | [type="search"]::-webkit-search-decoration { 300 | -webkit-appearance: none; 301 | } 302 | 303 | /** 304 | * 1. Correct the inability to style clickable types in iOS and Safari. 305 | * 2. Change font properties to `inherit` in Safari. 306 | */ 307 | 308 | ::-webkit-file-upload-button { 309 | -webkit-appearance: button; /* 1 */ 310 | font: inherit; /* 2 */ 311 | } 312 | 313 | /* Interactive 314 | ========================================================================== */ 315 | 316 | /* 317 | * Add the correct display in Edge, IE 10+, and Firefox. 318 | */ 319 | 320 | details { 321 | display: block; 322 | } 323 | 324 | /* 325 | * Add the correct display in all browsers. 326 | */ 327 | 328 | summary { 329 | display: list-item; 330 | } 331 | 332 | /* Misc 333 | ========================================================================== */ 334 | 335 | /** 336 | * Add the correct display in IE 10+. 337 | */ 338 | 339 | template { 340 | display: none; 341 | } 342 | 343 | /** 344 | * Add the correct display in IE 10. 345 | */ 346 | 347 | [hidden] { 348 | display: none; 349 | } 350 | --------------------------------------------------------------------------------