Skip to content

Commit 84f7c31

Browse files
committed
initial commit
0 parents  commit 84f7c31

File tree

13 files changed

+1480
-0
lines changed

13 files changed

+1480
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/
2+
/public/build/
3+
4+
.DS_Store

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["svelte.svelte-vscode"]
3+
}

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
*Psst — looking for a more complete solution? Check out [SvelteKit](https://kit.svelte.dev), the official framework for building web applications of all sizes, with a beautiful development experience and flexible filesystem-based routing.*
2+
3+
*Looking for a shareable component template instead? You can [use SvelteKit for that as well](https://kit.svelte.dev/docs#packaging) or the older [sveltejs/component-template](https://github.com/sveltejs/component-template)*
4+
5+
---
6+
7+
# svelte app
8+
9+
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template.
10+
11+
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
12+
13+
```bash
14+
npx degit sveltejs/template svelte-app
15+
cd svelte-app
16+
```
17+
18+
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
19+
20+
21+
## Get started
22+
23+
Install the dependencies...
24+
25+
```bash
26+
cd svelte-app
27+
npm install
28+
```
29+
30+
...then start [Rollup](https://rollupjs.org):
31+
32+
```bash
33+
npm run dev
34+
```
35+
36+
Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes.
37+
38+
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`.
39+
40+
If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense.
41+
42+
## Building and running in production mode
43+
44+
To create an optimised version of the app:
45+
46+
```bash
47+
npm run build
48+
```
49+
50+
You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com).
51+
52+
53+
## Single-page app mode
54+
55+
By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere.
56+
57+
If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json:
58+
59+
```js
60+
"start": "sirv public --single"
61+
```
62+
63+
## Using TypeScript
64+
65+
This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with:
66+
67+
```bash
68+
node scripts/setupTypeScript.js
69+
```
70+
71+
Or remove the script via:
72+
73+
```bash
74+
rm scripts/setupTypeScript.js
75+
```
76+
77+
If you want to use `baseUrl` or `path` aliases within your `tsconfig`, you need to set up `@rollup/plugin-alias` to tell Rollup to resolve the aliases. For more info, see [this StackOverflow question](https://stackoverflow.com/questions/63427935/setup-tsconfig-path-in-svelte).
78+
79+
## Deploying to the web
80+
81+
### With [Vercel](https://vercel.com)
82+
83+
Install `vercel` if you haven't already:
84+
85+
```bash
86+
npm install -g vercel
87+
```
88+
89+
Then, from within your project folder:
90+
91+
```bash
92+
cd public
93+
vercel deploy --name my-project
94+
```
95+
96+
### With [surge](https://surge.sh/)
97+
98+
Install `surge` if you haven't already:
99+
100+
```bash
101+
npm install -g surge
102+
```
103+
104+
Then, from within your project folder:
105+
106+
```bash
107+
npm run build
108+
surge public my-project.surge.sh
109+
```

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "svelte-app",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "rollup -c",
7+
"dev": "rollup -c -w",
8+
"start": "sirv public --no-clear",
9+
"check": "svelte-check --tsconfig ./tsconfig.json"
10+
},
11+
"devDependencies": {
12+
"@duckdb/duckdb-wasm": "^1.13.1-dev166.0",
13+
"@rollup/plugin-commonjs": "^17.0.0",
14+
"@rollup/plugin-node-resolve": "^11.0.0",
15+
"rollup": "^2.3.4",
16+
"rollup-plugin-css-only": "^3.1.0",
17+
"rollup-plugin-livereload": "^2.0.0",
18+
"rollup-plugin-svelte": "^7.0.0",
19+
"rollup-plugin-terser": "^7.0.0",
20+
"@rollup/plugin-url": "^6.1.0",
21+
"svelte": "^3.0.0",
22+
"svelte-check": "^2.0.0",
23+
"svelte-preprocess": "^4.0.0",
24+
"@rollup/plugin-typescript": "^8.0.0",
25+
"typescript": "^4.0.0",
26+
"tslib": "^2.0.0",
27+
"@tsconfig/svelte": "^2.0.0"
28+
},
29+
"dependencies": {
30+
"sirv-cli": "^2.0.0"
31+
}
32+
}

public/favicon.png

3.05 KB
Loading

public/global.css

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
html, body {
2+
position: relative;
3+
width: 100%;
4+
height: 100%;
5+
}
6+
7+
body {
8+
color: #333;
9+
margin: 0;
10+
padding: 8px;
11+
box-sizing: border-box;
12+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13+
}
14+
15+
a {
16+
color: rgb(0,100,200);
17+
text-decoration: none;
18+
}
19+
20+
a:hover {
21+
text-decoration: underline;
22+
}
23+
24+
a:visited {
25+
color: rgb(0,80,160);
26+
}
27+
28+
label {
29+
display: block;
30+
}
31+
32+
input, button, select, textarea {
33+
font-family: inherit;
34+
font-size: inherit;
35+
-webkit-padding: 0.4em 0;
36+
padding: 0.4em;
37+
margin: 0 0 0.5em 0;
38+
box-sizing: border-box;
39+
border: 1px solid #ccc;
40+
border-radius: 2px;
41+
}
42+
43+
input:disabled {
44+
color: #ccc;
45+
}
46+
47+
button {
48+
color: #333;
49+
background-color: #f4f4f4;
50+
outline: none;
51+
}
52+
53+
button:disabled {
54+
color: #999;
55+
}
56+
57+
button:not(:disabled):active {
58+
background-color: #ddd;
59+
}
60+
61+
button:focus {
62+
border-color: #666;
63+
}

public/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset='utf-8'>
5+
<meta name='viewport' content='width=device-width,initial-scale=1'>
6+
7+
<title>Svelte app</title>
8+
9+
<link rel='icon' type='image/png' href='/favicon.png'>
10+
<link rel='stylesheet' href='/global.css'>
11+
<link rel='stylesheet' href='/build/bundle.css'>
12+
13+
<script defer src='/build/bundle.js'></script>
14+
</head>
15+
16+
<body>
17+
</body>
18+
</html>

rollup.config.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import svelte from 'rollup-plugin-svelte';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import resolve from '@rollup/plugin-node-resolve';
4+
import url from '@rollup/plugin-url';
5+
import livereload from 'rollup-plugin-livereload';
6+
import { terser } from 'rollup-plugin-terser';
7+
import sveltePreprocess from 'svelte-preprocess';
8+
import typescript from '@rollup/plugin-typescript';
9+
import css from 'rollup-plugin-css-only';
10+
11+
const production = !process.env.ROLLUP_WATCH;
12+
13+
function serve() {
14+
let server;
15+
16+
function toExit() {
17+
if (server) server.kill(0);
18+
}
19+
20+
return {
21+
writeBundle() {
22+
if (server) return;
23+
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
24+
stdio: ['ignore', 'inherit', 'inherit'],
25+
shell: true
26+
});
27+
28+
process.on('SIGTERM', toExit);
29+
process.on('exit', toExit);
30+
}
31+
};
32+
}
33+
34+
export default {
35+
input: 'src/main.ts',
36+
output: {
37+
sourcemap: true,
38+
format: 'iife',
39+
name: 'app',
40+
file: 'public/build/bundle.js'
41+
},
42+
plugins: [
43+
svelte({
44+
preprocess: sveltePreprocess({ sourceMap: !production }),
45+
compilerOptions: {
46+
// enable run-time checks when not in production
47+
dev: !production
48+
}
49+
}),
50+
51+
url({
52+
fileName: '[dirname][hash][extname]',
53+
include: ['**/*.worker.js' ,'**/*.wasm', '**/*.svg', '**/*.png', '**/*.jp(e)?g', '**/*.gif', '**/*.webp'],
54+
publicPath: '/build/',
55+
}),
56+
57+
// we'll extract any component CSS out into
58+
// a separate file - better for performance
59+
css({ output: 'bundle.css' }),
60+
61+
// If you have external dependencies installed from
62+
// npm, you'll most likely need these plugins. In
63+
// some cases you'll need additional configuration -
64+
// consult the documentation for details:
65+
// https://github.com/rollup/plugins/tree/master/packages/commonjs
66+
resolve({
67+
browser: true,
68+
dedupe: ['svelte']
69+
}),
70+
commonjs(),
71+
typescript({
72+
sourceMap: !production,
73+
inlineSources: !production
74+
}),
75+
76+
// In dev mode, call `npm run start` once
77+
// the bundle has been generated
78+
!production && serve(),
79+
80+
// Watch the `public` directory and refresh the
81+
// browser on changes when not in production
82+
!production && livereload('public'),
83+
84+
// If we're building for production (npm run build
85+
// instead of npm run dev), minify
86+
production && terser()
87+
],
88+
watch: {
89+
clearScreen: false
90+
}
91+
};

src/App.svelte

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script lang="ts">
2+
import * as duckdb from '@duckdb/duckdb-wasm';
3+
4+
export let db: Promise<duckdb.AsyncDuckDB>;
5+
</script>
6+
7+
<main>
8+
{#await db}
9+
<h1>Instantiating...</h1>
10+
{:then db}
11+
<h1>Hello DuckDB-Wasm {duckdb.PACKAGE_VERSION}</h1>
12+
{:catch error}
13+
<p style="color: red">{error.message}</p>
14+
{/await}
15+
</main>
16+
17+
<style>
18+
main {
19+
text-align: center;
20+
padding: 1em;
21+
max-width: 240px;
22+
margin: 0 auto;
23+
}
24+
25+
h1 {
26+
color: #ff3e00;
27+
text-transform: uppercase;
28+
font-size: 4em;
29+
font-weight: 100;
30+
}
31+
32+
@media (min-width: 640px) {
33+
main {
34+
max-width: none;
35+
}
36+
}
37+
</style>

src/global.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types="svelte" />
2+
3+
declare module '*.wasm' {
4+
const value: any;
5+
export default value;
6+
}
7+
8+
declare module '*.worker.js' {
9+
const value: any;
10+
export default value;
11+
}

0 commit comments

Comments
 (0)