diff --git a/frontend/.vscode/extensions.json b/frontend/.vscode/extensions.json new file mode 100644 index 0000000..bdef820 --- /dev/null +++ b/frontend/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["svelte.svelte-vscode"] +} diff --git a/frontend/package.json b/frontend/package.json index e9e9def..de94d14 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,8 @@ "scripts": { "build": "rollup -c", "dev": "rollup -c -w", - "start": "sirv public" + "start": "sirv public", + "validate": "svelte-check" }, "devDependencies": { "@rollup/plugin-commonjs": "^14.0.0", @@ -13,9 +14,15 @@ "rollup-plugin-livereload": "^2.0.0", "rollup-plugin-svelte": "^6.0.0", "rollup-plugin-terser": "^7.0.0", - "svelte": "^3.0.0" + "svelte": "^3.0.0", + "svelte-check": "^1.0.0", + "svelte-preprocess": "^4.0.0", + "@rollup/plugin-typescript": "^6.0.0", + "typescript": "^3.9.3", + "tslib": "^2.0.0", + "@tsconfig/svelte": "^1.0.0" }, "dependencies": { "sirv-cli": "^1.0.0" } -} +} \ No newline at end of file diff --git a/frontend/rollup.config.js b/frontend/rollup.config.js index ecdc627..e5508aa 100644 --- a/frontend/rollup.config.js +++ b/frontend/rollup.config.js @@ -3,6 +3,8 @@ import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import livereload from 'rollup-plugin-livereload'; import { terser } from 'rollup-plugin-terser'; +import sveltePreprocess from 'svelte-preprocess'; +import typescript from '@rollup/plugin-typescript'; const production = !process.env.ROLLUP_WATCH; @@ -28,7 +30,7 @@ function serve() { } export default { - input: 'src/main.js', + input: 'src/main.ts', output: { sourcemap: true, format: 'iife', @@ -43,7 +45,8 @@ export default { // a separate file - better for performance css: css => { css.write('bundle.css'); - } + }, + preprocess: sveltePreprocess(), }), // If you have external dependencies installed from @@ -56,6 +59,10 @@ export default { dedupe: ['svelte'] }), commonjs(), + typescript({ + sourceMap: !production, + inlineSources: !production + }), // In dev mode, call `npm run start` once // the bundle has been generated diff --git a/frontend/scripts/setupTypeScript.js b/frontend/scripts/setupTypeScript.js deleted file mode 100644 index 123fc57..0000000 --- a/frontend/scripts/setupTypeScript.js +++ /dev/null @@ -1,128 +0,0 @@ -// @ts-check - -/** This script modifies the project to support TS code in .svelte files like: - - - - As well as validating the code for CI. - */ - -/** To work on this script: - rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template -*/ - -const fs = require("fs") -const path = require("path") -const { argv } = require("process") - -const projectRoot = argv[2] || path.join(__dirname, "..") - -// Add deps to pkg.json -const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8")) -packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, { - "svelte-check": "^1.0.0", - "svelte-preprocess": "^4.0.0", - "@rollup/plugin-typescript": "^6.0.0", - "typescript": "^3.9.3", - "tslib": "^2.0.0", - "@tsconfig/svelte": "^1.0.0" -}) - -// Add script for checking -packageJSON.scripts = Object.assign(packageJSON.scripts, { - "validate": "svelte-check" -}) - -// Write the package JSON -fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " ")) - -// mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too -const beforeMainJSPath = path.join(projectRoot, "src", "main.js") -const afterMainTSPath = path.join(projectRoot, "src", "main.ts") -fs.renameSync(beforeMainJSPath, afterMainTSPath) - -// Switch the app.svelte file to use TS -const appSveltePath = path.join(projectRoot, "src", "App.svelte") -let appFile = fs.readFileSync(appSveltePath, "utf8") -appFile = appFile.replace("
diff --git a/frontend/src/main.js b/frontend/src/main.ts similarity index 100% rename from frontend/src/main.js rename to frontend/src/main.ts diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json new file mode 100644 index 0000000..66aea81 --- /dev/null +++ b/frontend/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "@tsconfig/svelte/tsconfig.json", + + "include": ["src/**/*"], + "exclude": ["node_modules/*", "__sapper__/*", "public/*"], +} \ No newline at end of file