├── .gitignore
├── README.md
├── package.json
├── public
├── favicon.png
├── global.css
└── index.html
├── rollup.config.js
├── scripts
└── setupTypeScript.js
├── server.js
├── src
├── App.svelte
└── main.js
└── tailwind.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules/
2 | /public/build/
3 |
4 | .DS_Store
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ```bash
2 | npm install
3 | ```
4 |
5 | ...then start [Rollup](https://rollupjs.org):
6 |
7 | ```bash
8 | npm run dev
9 | ```
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
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 | },
10 | "devDependencies": {
11 | "@rollup/plugin-commonjs": "^17.0.0",
12 | "@rollup/plugin-node-resolve": "^11.0.0",
13 | "autoprefixer": "^10.4.2",
14 | "postcss": "^8.4.5",
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 | "svelte": "^3.0.0",
21 | "tailwindcss": "^3.0.15"
22 | },
23 | "dependencies": {
24 | "sirv-cli": "^2.0.0",
25 | "socket.io": "^4.4.1",
26 | "socket.io-client": "^4.4.1",
27 | "svelte-preprocess": "^4.10.1"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/public/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DevPioneer007/svelte-socket-chat/1cfce64c0519f9b934d3145cc0593cb923f98403/public/favicon.png
--------------------------------------------------------------------------------
/public/global.css:
--------------------------------------------------------------------------------
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 | }
64 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Svelte app
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte';
2 | import commonjs from '@rollup/plugin-commonjs';
3 | import resolve from '@rollup/plugin-node-resolve';
4 | import livereload from 'rollup-plugin-livereload';
5 | import { terser } from 'rollup-plugin-terser';
6 | import css from 'rollup-plugin-css-only';
7 | import sveltePreprocess from 'svelte-preprocess';
8 | import tailwindcss from 'tailwindcss';
9 | import autoprefixer from 'autoprefixer';
10 | import postcss from 'postcss';
11 |
12 | const production = !process.env.ROLLUP_WATCH;
13 |
14 | function serve() {
15 | let server;
16 |
17 | function toExit() {
18 | if (server) server.kill(0);
19 | }
20 |
21 | return {
22 | writeBundle() {
23 | if (server) return;
24 | server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
25 | stdio: ['ignore', 'inherit', 'inherit'],
26 | shell: true
27 | });
28 |
29 | process.on('SIGTERM', toExit);
30 | process.on('exit', toExit);
31 | }
32 | };
33 | }
34 |
35 | export default {
36 | input: 'src/main.js',
37 | output: {
38 | sourcemap: true,
39 | format: 'iife',
40 | name: 'app',
41 | file: 'public/build/bundle.js'
42 | },
43 | plugins: [
44 | svelte({
45 | compilerOptions: {
46 | // enable run-time checks when not in production
47 | dev: !production
48 | },
49 | preprocess: sveltePreprocess({
50 | postcss: postcss({
51 | plugins: [tailwindcss(), autoprefixer()],
52 | }),
53 | }),
54 | }),
55 | // we'll extract any component CSS out into
56 | // a separate file - better for performance
57 | css({ output: 'bundle.css' }),
58 |
59 | // If you have external dependencies installed from
60 | // npm, you'll most likely need these plugins. In
61 | // some cases you'll need additional configuration -
62 | // consult the documentation for details:
63 | // https://github.com/rollup/plugins/tree/master/packages/commonjs
64 | resolve({
65 | browser: true,
66 | dedupe: ['svelte']
67 | }),
68 | commonjs(),
69 |
70 | // In dev mode, call `npm run start` once
71 | // the bundle has been generated
72 | !production && serve(),
73 |
74 | // Watch the `public` directory and refresh the
75 | // browser on changes when not in production
76 | !production && livereload('public'),
77 |
78 | // If we're building for production (npm run build
79 | // instead of npm run dev), minify
80 | production && terser()
81 | ],
82 | watch: {
83 | clearScreen: false
84 | }
85 | };
86 |
--------------------------------------------------------------------------------
/scripts/setupTypeScript.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 |
3 | /** This script modifies the project to support TS code in .svelte files like:
4 |
5 |
8 |
9 | As well as validating the code for CI.
10 | */
11 |
12 | /** To work on this script:
13 | rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template
14 | */
15 |
16 | const fs = require("fs")
17 | const path = require("path")
18 | const { argv } = require("process")
19 |
20 | const projectRoot = argv[2] || path.join(__dirname, "..")
21 |
22 | // Add deps to pkg.json
23 | const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8"))
24 | packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, {
25 | "svelte-check": "^2.0.0",
26 | "svelte-preprocess": "^4.0.0",
27 | "@rollup/plugin-typescript": "^8.0.0",
28 | "typescript": "^4.0.0",
29 | "tslib": "^2.0.0",
30 | "@tsconfig/svelte": "^2.0.0"
31 | })
32 |
33 | // Add script for checking
34 | packageJSON.scripts = Object.assign(packageJSON.scripts, {
35 | "check": "svelte-check --tsconfig ./tsconfig.json"
36 | })
37 |
38 | // Write the package JSON
39 | fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " "))
40 |
41 | // mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too
42 | const beforeMainJSPath = path.join(projectRoot, "src", "main.js")
43 | const afterMainTSPath = path.join(projectRoot, "src", "main.ts")
44 | fs.renameSync(beforeMainJSPath, afterMainTSPath)
45 |
46 | // Switch the app.svelte file to use TS
47 | const appSveltePath = path.join(projectRoot, "src", "App.svelte")
48 | let appFile = fs.readFileSync(appSveltePath, "utf8")
49 | appFile = appFile.replace("
18 |
19 |
20 |
21 |
22 |
Chat Application
23 |
24 | {#each messages as message}
25 |
{message}
26 | {/each}
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import App from './App.svelte';
2 |
3 | //
4 | //
5 | const app = new App({
6 | target: document.body,
7 | props: {
8 | name: 'world'
9 | }
10 | });
11 |
12 | export default app;
--------------------------------------------------------------------------------
/tailwind.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | content: ["./src/**/*.svelte"],
3 | theme: {
4 | extend: {},
5 | },
6 | plugins: [],
7 | }
8 |
--------------------------------------------------------------------------------