서준혁

Link express with svelte

1 -/node_modules/ 1 +# Logs
2 -/public/build/ 2 +logs
3 +*.log
4 +npm-debug.log*
5 +yarn-debug.log*
6 +yarn-error.log*
7 +lerna-debug.log*
3 8
4 -.DS_Store 9 +# Diagnostic reports (https://nodejs.org/api/report.html)
10 +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11 +
12 +# Runtime data
13 +pids
14 +*.pid
15 +*.seed
16 +*.pid.lock
17 +
18 +# Directory for instrumented libs generated by jscoverage/JSCover
19 +lib-cov
20 +
21 +# Coverage directory used by tools like istanbul
22 +coverage
23 +*.lcov
24 +
25 +# nyc test coverage
26 +.nyc_output
27 +
28 +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29 +.grunt
30 +
31 +# Bower dependency directory (https://bower.io/)
32 +bower_components
33 +
34 +# node-waf configuration
35 +.lock-wscript
36 +
37 +# Compiled binary addons (https://nodejs.org/api/addons.html)
38 +build/Release
39 +
40 +# Dependency directories
41 +node_modules/
42 +jspm_packages/
43 +
44 +# TypeScript v1 declaration files
45 +typings/
46 +
47 +# TypeScript cache
48 +*.tsbuildinfo
49 +
50 +# Optional npm cache directory
51 +.npm
52 +
53 +# Optional eslint cache
54 +.eslintcache
55 +
56 +# Microbundle cache
57 +.rpt2_cache/
58 +.rts2_cache_cjs/
59 +.rts2_cache_es/
60 +.rts2_cache_umd/
61 +
62 +# Optional REPL history
63 +.node_repl_history
64 +
65 +# Output of 'npm pack'
66 +*.tgz
67 +
68 +# Yarn Integrity file
69 +.yarn-integrity
70 +
71 +# dotenv environment variables file
72 +.env
73 +.env.test
74 +
75 +# parcel-bundler cache (https://parceljs.org/)
76 +.cache
77 +
78 +# Next.js build output
79 +.next
80 +
81 +# Nuxt.js build / generate output
82 +.nuxt
83 +dist
84 +
85 +# Gatsby files
86 +.cache/
87 +# Comment in the public line in if your project uses Gatsby and *not* Next.js
88 +# https://nextjs.org/blog/next-9-1#public-directory-support
89 +# public
90 +
91 +# vuepress build output
92 +.vuepress/dist
93 +
94 +# Serverless directories
95 +.serverless/
96 +
97 +# FuseBox cache
98 +.fusebox/
99 +
100 +# DynamoDB Local files
101 +.dynamodb/
102 +
103 +# TernJS port file
104 +.tern-port
......
1 +This is free and unencumbered software released into the public domain.
2 +
3 +Anyone is free to copy, modify, publish, use, compile, sell, or
4 +distribute this software, either in source code form or as a compiled
5 +binary, for any purpose, commercial or non-commercial, and by any
6 +means.
7 +
8 +In jurisdictions that recognize copyright laws, the author or authors
9 +of this software dedicate any and all copyright interest in the
10 +software to the public domain. We make this dedication for the benefit
11 +of the public at large and to the detriment of our heirs and
12 +successors. We intend this dedication to be an overt act of
13 +relinquishment in perpetuity of all present and future rights to this
14 +software under copyright law.
15 +
16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 +OTHER DEALINGS IN THE SOFTWARE.
23 +
24 +For more information, please refer to <https://unlicense.org>
1 -type "npm run dev" in terminal to run
...\ No newline at end of file ...\ No newline at end of file
1 +# svelte-base
2 +Basic svelte and express template I use for my application
3 +
4 +## Commands:
5 +- `npm start` : Build the app in dev mode and launch the server
6 +- `npm run build` : Build the app
7 +- `npm run server` : Launch the server
8 +- `npm run release` : Build the app for production
9 +- `npm run dev` : Launch the server for test or developing
10 +
11 +You can change the port of the application in the server.js file
......
1 -.DS_Store
2 -thumbs.db
3 -*.log
4 -node_modules/
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
1 { 1 {
2 - "name": "svelte-app", 2 + "name": "svelte-base",
3 "version": "1.0.0", 3 "version": "1.0.0",
4 - "private": true, 4 + "description": "Basic svelte and express template I use for my application",
5 + "main": "server.js",
5 "scripts": { 6 "scripts": {
6 - "build": "rollup -c", 7 + "build": "webpack",
7 - "dev": "rollup -c -w", 8 + "release": "cross-env NODE_ENV=production webpack",
8 - "start": "sirv public --no-clear --host 0.0.0.0" 9 + "server": "node server.js",
10 + "start": "npm run build & npm run server",
11 + "dev": "nodemon --watch ./src -e svelte,js,json --exec npm start"
9 }, 12 },
10 - "devDependencies": { 13 + "repository": {
11 - "@rollup/plugin-commonjs": "^17.0.0", 14 + "type": "git",
12 - "@rollup/plugin-node-resolve": "^11.0.0", 15 + "url": "git+https://github.com/Bigaston/svelte-base.git"
13 - "rollup": "^2.3.4", 16 + },
14 - "rollup-plugin-css-only": "^3.1.0", 17 + "author": "Bigaston",
15 - "rollup-plugin-livereload": "^2.0.0", 18 + "license": "UNLICENSED",
16 - "rollup-plugin-svelte": "^7.0.0", 19 + "bugs": {
17 - "rollup-plugin-terser": "^7.0.0", 20 + "url": "https://github.com/Bigaston/svelte-base/issues"
18 - "svelte": "^3.0.0"
19 }, 21 },
22 + "homepage": "https://github.com/Bigaston/svelte-base#readme",
20 "dependencies": { 23 "dependencies": {
21 - "engine.io-parser": "^5.0.1", 24 + "express": "^4.17.1",
22 "jquery": "^3.6.0", 25 "jquery": "^3.6.0",
23 - "sirv-cli": "^1.0.0" 26 + "nodemon": "^2.0.15",
27 + "socket.io": "^4.3.2",
28 + "socket.io-client": "^4.3.2"
29 + },
30 + "devDependencies": {
31 + "cross-env": "^7.0.2",
32 + "css-loader": "^3.5.2",
33 + "style-loader": "^1.1.3",
34 + "svelte": "^3.20.1",
35 + "svelte-loader": "^2.13.6",
36 + "webpack": "^4.42.1",
37 + "webpack-cli": "^3.3.11"
24 } 38 }
25 } 39 }
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 -<html lang="en"> 2 +<html lang="ko">
3 <head> 3 <head>
4 <meta charset='utf-8'> 4 <meta charset='utf-8'>
5 <meta name='viewport' content='width=device-width,initial-scale=1'> 5 <meta name='viewport' content='width=device-width,initial-scale=1'>
6 + <link rel='icon' type='image/png' href='/public/favicon.png'>
7 + <link rel='stylesheet' href='/public/global.css'>
6 8
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 type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=046d27f1430524731d3ec6870f0c8923"></script>
14 - <script defer src='/build/bundle.js'></script>
15 </head> 9 </head>
16 10
17 <body> 11 <body>
12 + <noscript>
13 + <p>This website need JavaScript to work</p>
14 + </noscript>
15 +
16 + <main></main>
17 +
18 + <script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=046d27f1430524731d3ec6870f0c8923"></script>
19 + <script src='./public/build/bundle.js'></script>
18 </body> 20 </body>
19 </html> 21 </html>
......
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 -
8 -const production = !process.env.ROLLUP_WATCH;
9 -
10 -function serve() {
11 - let server;
12 -
13 - function toExit() {
14 - if (server) server.kill(0);
15 - }
16 -
17 - return {
18 - writeBundle() {
19 - if (server) return;
20 - server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
21 - stdio: ['ignore', 'inherit', 'inherit'],
22 - shell: true
23 - });
24 -
25 - process.on('SIGTERM', toExit);
26 - process.on('exit', toExit);
27 - }
28 - };
29 -}
30 -
31 -export default {
32 - input: 'src/main.js',
33 - output: {
34 - sourcemap: true,
35 - format: 'iife',
36 - name: 'app',
37 - file: 'public/build/bundle.js'
38 - },
39 - plugins: [
40 - svelte({
41 - compilerOptions: {
42 - // enable run-time checks when not in production
43 - dev: !production
44 - }
45 - }),
46 - // we'll extract any component CSS out into
47 - // a separate file - better for performance
48 - css({ output: 'bundle.css' }),
49 -
50 - // If you have external dependencies installed from
51 - // npm, you'll most likely need these plugins. In
52 - // some cases you'll need additional configuration -
53 - // consult the documentation for details:
54 - // https://github.com/rollup/plugins/tree/master/packages/commonjs
55 - resolve({
56 - browser: true,
57 - dedupe: ['svelte']
58 - }),
59 - commonjs(),
60 -
61 - // In dev mode, call `npm run start` once
62 - // the bundle has been generated
63 - !production && serve(),
64 -
65 - // Watch the `public` directory and refresh the
66 - // browser on changes when not in production
67 - !production && livereload('public'),
68 -
69 - // If we're building for production (npm run build
70 - // instead of npm run dev), minify
71 - production && terser()
72 - ],
73 - watch: {
74 - clearScreen: false
75 - }
76 -};
1 -// @ts-check
2 -
3 -/** This script modifies the project to support TS code in .svelte files like:
4 -
5 - <script lang="ts">
6 - export let name: string;
7 - </script>
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("<script>", '<script lang="ts">')
50 -appFile = appFile.replace("export let name;", 'export let name: string;')
51 -fs.writeFileSync(appSveltePath, appFile)
52 -
53 -// Edit rollup config
54 -const rollupConfigPath = path.join(projectRoot, "rollup.config.js")
55 -let rollupConfig = fs.readFileSync(rollupConfigPath, "utf8")
56 -
57 -// Edit imports
58 -rollupConfig = rollupConfig.replace(`'rollup-plugin-terser';`, `'rollup-plugin-terser';
59 -import sveltePreprocess from 'svelte-preprocess';
60 -import typescript from '@rollup/plugin-typescript';`)
61 -
62 -// Replace name of entry point
63 -rollupConfig = rollupConfig.replace(`'src/main.js'`, `'src/main.ts'`)
64 -
65 -// Add preprocessor
66 -rollupConfig = rollupConfig.replace(
67 - 'compilerOptions:',
68 - 'preprocess: sveltePreprocess({ sourceMap: !production }),\n\t\t\tcompilerOptions:'
69 -);
70 -
71 -// Add TypeScript
72 -rollupConfig = rollupConfig.replace(
73 - 'commonjs(),',
74 - 'commonjs(),\n\t\ttypescript({\n\t\t\tsourceMap: !production,\n\t\t\tinlineSources: !production\n\t\t}),'
75 -);
76 -fs.writeFileSync(rollupConfigPath, rollupConfig)
77 -
78 -// Add TSConfig
79 -const tsconfig = `{
80 - "extends": "@tsconfig/svelte/tsconfig.json",
81 -
82 - "include": ["src/**/*"],
83 - "exclude": ["node_modules/*", "__sapper__/*", "public/*"]
84 -}`
85 -const tsconfigPath = path.join(projectRoot, "tsconfig.json")
86 -fs.writeFileSync(tsconfigPath, tsconfig)
87 -
88 -// Add global.d.ts
89 -const dtsPath = path.join(projectRoot, "src", "global.d.ts")
90 -fs.writeFileSync(dtsPath, `/// <reference types="svelte" />`)
91 -
92 -// Delete this script, but not during testing
93 -if (!argv[2]) {
94 - // Remove the script
95 - fs.unlinkSync(path.join(__filename))
96 -
97 - // Check for Mac's DS_store file, and if it's the only one left remove it
98 - const remainingFiles = fs.readdirSync(path.join(__dirname))
99 - if (remainingFiles.length === 1 && remainingFiles[0] === '.DS_store') {
100 - fs.unlinkSync(path.join(__dirname, '.DS_store'))
101 - }
102 -
103 - // Check if the scripts folder is empty
104 - if (fs.readdirSync(path.join(__dirname)).length === 0) {
105 - // Remove the scripts folder
106 - fs.rmdirSync(path.join(__dirname))
107 - }
108 -}
109 -
110 -// Adds the extension recommendation
111 -fs.mkdirSync(path.join(projectRoot, ".vscode"), { recursive: true })
112 -fs.writeFileSync(path.join(projectRoot, ".vscode", "extensions.json"), `{
113 - "recommendations": ["svelte.svelte-vscode"]
114 -}
115 -`)
116 -
117 -console.log("Converted to TypeScript.")
118 -
119 -if (fs.existsSync(path.join(projectRoot, "node_modules"))) {
120 - console.log("\nYou will need to re-run your dependency manager to get started.")
121 -}
1 +const express = require('express')
2 +const path = require("path")
3 +
4 +var app = express()
5 +
6 +const PORT = 1697;
7 +
8 +app.use("/public", express.static('./public'));
9 +
10 +app.get("/*", (req, res) => {
11 + res.sendFile(path.join(__dirname, "./public/index.html"))
12 +})
13 +
14 +var serv = app.listen(PORT, () => console.log(`Serveur lauched on port ${PORT}`))
...@@ -5,12 +5,16 @@ ...@@ -5,12 +5,16 @@
5 export let sidebar_show = false; 5 export let sidebar_show = false;
6 let side = "right"; 6 let side = "right";
7 7
8 - function showBar() { 8 + function hide() {
9 - sidebar_show = !sidebar_show; 9 + if (window.scrollY < 400) {
10 + sidebar_show = true
11 + } else {
12 + sidebar_show = false
13 + }
10 } 14 }
11 </script> 15 </script>
12 16
13 - 17 +<svelte:window on:scroll={hide}></svelte:window>
14 <SideBar bind:show={sidebar_show} {side}> 18 <SideBar bind:show={sidebar_show} {side}>
15 {festa.title} 19 {festa.title}
16 </SideBar> 20 </SideBar>
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 border-right: 1px solid #aaa; 19 border-right: 1px solid #aaa;
20 background: #fff; 20 background: #fff;
21 overflow-y: auto; 21 overflow-y: auto;
22 + padding: 2rem 1rem 0.6rem;
22 width: 330px; 23 width: 330px;
23 z-index: 900; 24 z-index: 900;
24 } 25 }
......
1 -<!DOCTYPE html>
2 -<html>
3 -<head>
4 - <meta charset="utf-8">
5 - <script src="http://code.jquery.com/jquery-3.6.0.min.js"></script>
6 - <title>다음 지도 API</title>
7 -</head>
8 -<body>
9 - <div id="map" style="width:100%;height:100vh;"></div>
10 -
11 - <script src="https://dapi.kakao.com/v2/maps/sdk.js?appkey=046d27f1430524731d3ec6870f0c8923"></script>
12 - <script>
13 -
14 - var url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=A&numOfRows=12&pageNo=1&_type=json";
15 - $.getJSON(url,function(data){
16 - console.log(data);
17 - var mapContainer = document.getElementById('map'), // 지도를 표시할 div
18 - mapOption = {
19 - center: new kakao.maps.LatLng(37.56682, 126.97865), // 지도의 중심좌표
20 - level: 12, // 지도의 확대 레벨
21 - mapTypeId : kakao.maps.MapTypeId.ROADMAP // 지도종류
22 - };
23 -
24 - var markers= [];
25 - // 지도를 생성한다
26 - console.log(data.response.body.items.item.length);
27 - var map = new kakao.maps.Map(mapContainer, mapOption);
28 - for(var i = 0; i<data.response.body.items.item.length;i++){
29 - // 지도에 마커를 생성하고 표시한다
30 - var marker = new kakao.maps.Marker({
31 - position: new kakao.maps.LatLng(data.response.body.items.item[i].mapy, data.response.body.items.item[i].mapx), // 마커의 좌표
32 - map: map // 마커를 표시할 지도 객체
33 - });
34 - markers.push(marker);
35 - // 마커 위에 표시할 인포윈도우를 생성한다
36 -
37 - };
38 -
39 - for(var i = 0; i<data.response.body.items.item.length;i++){ // 왜 9까지 밖에 안되누 ㅠㅠ
40 - var infowindow = new kakao.maps.InfoWindow({
41 - content : '<div style="padding:5px;">'+data.response.body.items.item[i].title+'</div>' // 인포윈도우에 표시할 내용
42 - });
43 - infowindow.open(map, markers[i]);
44 - }
45 - })
46 -
47 -
48 - </script>
49 -</body>
50 -</html>
...\ No newline at end of file ...\ No newline at end of file
1 +const path = require('path');
2 +
3 +const mode = process.env.NODE_ENV || 'development';
4 +const prod = mode === 'production';
5 +
6 +module.exports = {
7 + entry: {
8 + bundle: ['./src/main.js']
9 + },
10 + resolve: {
11 + alias: {
12 + svelte: path.resolve('node_modules', 'svelte')
13 + },
14 + extensions: ['.mjs', '.js', '.svelte'],
15 + mainFields: ['svelte', 'browser', 'module', 'main']
16 + },
17 + output: {
18 + path: __dirname + '/public/build',
19 + filename: '[name].js',
20 + chunkFilename: '[name].[id].js'
21 + },
22 + module: {
23 + rules: [
24 + {
25 + test: /\.svelte$/,
26 + use: {
27 + loader: 'svelte-loader',
28 + options: {
29 + emitCss: true,
30 + hotReload: true
31 + }
32 + }
33 + },
34 + {
35 + test: /\.css$/,
36 + use: ['style-loader', 'css-loader']
37 + }
38 + ]
39 + },
40 + mode,
41 + plugins: [],
42 + devtool: prod ? false: 'source-map'
43 +};