Skip to content

Commit 7269101

Browse files
committed
feat: counter library example
1 parent 288ca81 commit 7269101

File tree

16 files changed

+1370
-0
lines changed

16 files changed

+1370
-0
lines changed

examples/counter-library/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
vite.config.js.timestamp-*
10+
vite.config.ts.timestamp-*

examples/counter-library/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
10+
# Ignore files for PNPM, NPM and YARN
11+
pnpm-lock.yaml
12+
package-lock.json
13+
yarn.lock

examples/counter-library/.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"useTabs": true,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"printWidth": 100,
6+
"plugins": ["prettier-plugin-svelte"],
7+
"pluginSearchDirs": ["."],
8+
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
9+
}

examples/counter-library/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Counter Library
2+
3+
A Svelte library created with [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
4+
5+
## Developing
6+
7+
Install dependencies with `npm install` (or `pnpm install` or `yarn`), and start a development server:
8+
9+
```bash
10+
npm run dev
11+
```
12+
13+
Develop your library within `src/lib`. Reexport everything that should be publicly available from `src/lib/index.js`. Preview/showcase your work within `src/routes`. In this example, there's one Counter component.
14+
15+
## Building
16+
17+
To prepare the library for release, run
18+
19+
```bash
20+
npm run package
21+
```
22+
23+
This will output everything that's inside `src/lib` into the `dist` folder, transforming TypeScript to JavaScript and creating type definitions. To publish the library to npm, run
24+
25+
```bash
26+
npm publish
27+
```
28+
29+
The result would be available for others as
30+
31+
```svelte
32+
<script>
33+
import { Counter } from 'your-library';
34+
</script>
35+
36+
<Counter />
37+
```
38+
39+
## More info
40+
41+
Read the [packaging docs](https://kit.svelte.dev/docs/packaging) for more info on how to create a Svelte library.

examples/counter-library/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "counter-library",
3+
"version": "0.0.1",
4+
"scripts": {
5+
"dev": "vite dev",
6+
"build": "vite build && npm run package",
7+
"preview": "vite preview",
8+
"package": "svelte-kit sync && svelte-package && publint",
9+
"prepublishOnly": "npm run package && publint",
10+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
11+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12+
"lint": "prettier --plugin-search-dir . --check .",
13+
"format": "prettier --plugin-search-dir . --write ."
14+
},
15+
"exports": {
16+
".": {
17+
"types": "./dist/index.d.ts",
18+
"svelte": "./dist/index.js"
19+
}
20+
},
21+
"peerDependencies": {
22+
"svelte": "^3.54.0"
23+
},
24+
"devDependencies": {
25+
"@sveltejs/adapter-auto": "^2.0.0",
26+
"@sveltejs/kit": "^1.5.0",
27+
"@sveltejs/package": "^2.0.0",
28+
"prettier": "^2.8.0",
29+
"prettier-plugin-svelte": "^2.8.1",
30+
"publint": "^0.1.9",
31+
"svelte": "^3.54.0",
32+
"svelte-check": "^3.0.1",
33+
"tslib": "^2.4.1",
34+
"typescript": "^4.9.3",
35+
"vite": "^4.0.0"
36+
},
37+
"svelte": "./dist/index.js",
38+
"types": "./dist/index.d.ts",
39+
"type": "module"
40+
}

examples/counter-library/src/app.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// See https://kit.svelte.dev/docs/types#app
2+
// for information about these interfaces
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface Platform {}
9+
}
10+
}
11+
12+
export {};

examples/counter-library/src/app.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
%sveltekit.head%
8+
</head>
9+
<body>
10+
<div>%sveltekit.body%</div>
11+
</body>
12+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
import { createEventDispatcher } from "svelte";
3+
4+
export let count = 0;
5+
6+
const dispatch = createEventDispatcher<{ change: number }>();
7+
8+
function increment() {
9+
count++;
10+
dispatch('change', count);
11+
}
12+
13+
function decrement() {
14+
count--;
15+
dispatch('change', count);
16+
}
17+
</script>
18+
19+
<slot {count}><p>The count is {count}</p></slot>
20+
<button on:click={increment}>Increment</button>
21+
<button on:click={decrement}>Decrement</button>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Reexport your entry components here
2+
export { default as Counter } from './Counter.svelte';

0 commit comments

Comments
 (0)