์ฐ๋ฆฌ๋ ๋น์ ์ด svelte ํ๋ก์ ํธ๋ฅผ ๋ง๋ค๊ณ svelte-preprocessor๋ฅผ ์ํ ๋
ธ๋ ๋ชจ๋์ ํฌํจํ์ฌ lang='ts'
์ง์์ด ์๋ํ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ์๋ํ๋์ง ํ์ธํ๊ณ ๋ฉ๋ชจ๋ฅผ ์ถ๊ฐํ์ธ์ ๐
๋งค๋ ฅ์ฒ๋ผ ์๋ํฉ๋๋ค https://github.com/dummdidumm/template
svelte-preprocess typescript tslib @rollup/plugin-typescript
rollup.config.js
๊ฐ์ :// ...
import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
// ...
plugins: [
svelte({
// ...
preprocess: sveltePreprocess(), // <--
}),
// ...
commonjs(),
typescript(), // <-- added below commonjs
// ...
main.js
)์ ์ฌ์ ํ โโ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์ด์ด์ผ ํฉ๋๋ค.์ด๊ฒ์ ์๋ํ๊ณ ํ์ธํ์ต๋๋ค!
__๋ชจ๋ ์์
์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค!__ ํ
ํ๋ฆฟ์ tsconfig.json
ํ์ผ์ด ๋๋ฝ๋ ๊ฒ ๊ฐ์ต๋๋ค.
rollup v1.32.1
bundles src/main.js โ public/build/bundle.js...
(!) Plugin typescript: @rollup/plugin-typescript TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.
[!] (plugin typescript) Error: @rollup/plugin-typescript: Couldn't process compiler options
Error: @rollup/plugin-typescript: Couldn't process compiler options
at error (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/node-entry.js:5400:30)
๋ค์ tsconfig.json
๋ด์ฉ ๊ด์ฐฎ๋์?
{
"include": ["src/**/*"],
"exclude": ["node_modules/*"],
"compilerOptions": {
"target": "es2017",
"types": ["svelte"],
"moduleResolution": "node"
}
}
rollup v1.32.1
bundles src/main.js โ public/build/bundle.js...
(!) Plugin typescript: @rollup/plugin-typescript TS18003: No inputs were found in config file '/Users/bgd/Documents/Projects/Essential modules/tsconfig.json'. Specified 'include' paths were '["src/**/*"]' and 'exclude' paths were '["node_modules/*"]'.
[!] (plugin typescript) Error: @rollup/plugin-typescript: Couldn't process compiler options
Error: @rollup/plugin-typescript: Couldn't process compiler options
at error (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/node-entry.js:5400:30)
at throwPluginError (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/node-entry.js:11878:12)
at Object.error (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/node-entry.js:12912:24)
at emitParsedOptionsErrors (/Users/bgd/Documents/Projects/Essential modules/node_modules/@rollup/plugin-typescript/dist/index.js:310:17)
at Object.buildStart (/Users/bgd/Documents/Projects/Essential modules/node_modules/@rollup/plugin-typescript/dist/index.js:469:13)
at /Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/node-entry.js:13117:25
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Promise.all (index 2)
์ถ์ฒ: https://codechips.me/how-to-use-typescript-with-svelte/
์ฌ๋ฏธ์๋ค์... tsconfig.json
๋ ํ์์์ด์ ๊ทธ๋ฅ ๋๋์ต๋๋ค. ๋๋ ๊ทธ ์ค๋ฅ ์ค ํ๋๋ฅผ ์ป์ง ๋ชปํ์ต๋๋ค.
sapper์ ํจ๊ป ์ฌ์ฉํ๋ ค๊ณ ํ๋๋ฐ ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
$ sapper dev
โ server
@rollup/plugin-typescript: Couldn't process compiler options
โ client
@rollup/plugin-typescript: Couldn't process compiler options
internal/modules/cjs/loader.js:584
throw err;
export const preprocess = sveltePreprocess({
postcss: true,
style: sass(),
})
plugins: [
...
...
svelte({
dev,
hydratable: true,
emitCss: true,
preprocess,
}),
...
....
commonjs(),
typescript(),
ํ
ํ๋ฆฟ์ IDE๊ฐ svelte์ ํจ๊ป ๊ธฐ๋ณธ์ ์ผ๋ก ์๋ํ๋ค๋ ๊ฐ๋
์ฆ๋ช
์ผ๋ก ์๋๋์์ต๋๋ค. tsconfig.json
๋๋ Sapper์ ๊ฐ์ ๊ฒ์ ๊ทธ ๋น์ ์ ๋ง์์ ์์์ต๋๋ค.
์ผ๋ฐ์ ์ผ๋ก Sapper๊ฐ ํฌํจ๋ Typescript๋ ํ์ฌ ์ ์ง์๋์ง ์์ต๋๋ค. @benmccann์ ๋ํด ๋ ์๊ณ ์์ต๋๊น?
Sapper์์ ์์ ์ด ๊ฑฐ์ ์๋ฃ๋์์ต๋๋ค. ๋ ๊ฐ์ง ์ฃผ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
master
์์ ์์ ๋์์ง๋ง ์์ง ๋ฆด๋ฆฌ์ค๋์ง ์์์ต๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ "์ปดํ์ผ๋ฌ ์ต์
์ ์ฒ๋ฆฌํ ์ ์์"๋ง ํ์๋๊ณ ๋ ์ ์ฉํ ๋ฉ์์ง๊ฐ ํ์๋์ง ์์ ์ ์์ต๋๋ค.preload
๋ ํ
ํ๋ฆฟ์๋ TypeScript๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ๋ณด๋ฅ ์ค์ธ PR์ด ์์ต๋๋ค: https://github.com/sveltejs/sapper/pull/1222์์ ์์ ์ฌํญ์ด ๋ณํฉ๋์ด ๋ฆด๋ฆฌ์ค๋ ๋๊น์ง TypeScript์์ ์ฝ๋ฉํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ Sapper ํฌํฌ๋ฅผ ๋ง๋ค์์ต๋๋ค. https://github.com/sveltejs/sapper/issues/760#issuecomment -634423518
@dummdidumm ๋น ๋ฅธ ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค ๐
๋ถํํ๋ ๋ฌธ์ ๊ฐ ์ง์๋ฉ๋๋ค.
์ด๊ฒ์ ๋ด package.json
ํ์ผ์
๋๋ค.
{
"name": "svelte-app",
"version": "0.0.1",
"scripts": {
"build": "npm install && rollup -c",
"dev": "npm install && rollup -c -w",
"start": "sirv public --single",
"lint": "eslint . --ext .js,.svelte; exit 0",
"lint-report": "eslint . --ext .js,.svelte -o ./.eslint-report.html -f html; exit 0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-node-resolve": "^7.0.0",
"@rollup/plugin-typescript": "^4.1.2",
"eslint": "^7.0.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-svelte3": "^2.7.3",
"rollup": "^1.20.0",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^5.1.2",
"svelte": "^3.0.0",
"svelte-preprocess": "^3.8.0",
"tslib": "^2.0.0",
"typescript": "^3.9.5"
},
"dependencies": {
"page": "^1.11.6",
"sirv-cli": "^0.4.4"
}
}
rollup.config.js
ํ์ผ:
import svelte from "rollup-plugin-svelte";
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 autoPreprocess from "svelte-preprocess";
import typescript from "@rollup/plugin-typescript";
const production = !process.env.ROLLUP_WATCH;
export default {
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/bundle.js"
},
plugins: [
svelte({
// enable run-time checks when not in production
dev: !production,
// we'll extract any component CSS out into
// a separate file - better for performance
css: css => {
css.write("public/build/bundle.css");
},
preprocess: autoPreprocess()
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ["svelte"]
}),
commonjs(),
typescript(),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload("public"),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
};
function serve () {
let started = false;
return {
writeBundle () {
if (!started) {
started = true;
require("child_process").spawn("npm", ["run", "start", "--", "--dev"], {
stdio: ["ignore", "inherit", "inherit"],
shell: true
});
}
}
};
}
์ค๋ฅ๋ฅผ ์ง์ ์ฌํํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ package.json
๋ฅผ ๋ณด๋ฉด 2.x ๋์ ๋กค์
1.x ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ชจ๋ ์ข
์์ฑ์ ์ต์ ๋ฒ์ ์ผ๋ก ์ถฉ๋ํ๋ฉด ํด๊ฒฐ๋ ์ ์์ต๋๊น?
@dummdidumm ๋ชจ๋ ์ข
์์ฑ์ ์ต์ ๋ฒ์ ์ผ๋ก ์ถฉ๋ tsconfig.json
ํ์ผ, package-lock.json
ํ์ผ ๋ฐ node_modules
ํด๋๋ฅผ ์ญ์ ํ์ต๋๋ค. ๋ฌธ์ ๊ฐ ์ง์๋ฉ๋๋ค ๐ค
์๋ฌ ๋ฉ์์ง:
rollup v2.15.0
bundles src/main.js โ public/build/bundle.js...
(!) Plugin typescript: @rollup/plugin-typescript TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.
[!] (plugin typescript) Error: @rollup/plugin-typescript: Couldn't process compiler options
Error: @rollup/plugin-typescript: Couldn't process compiler options
at error (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/rollup.js:213:30)
at throwPluginError (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/rollup.js:17117:12)
at Object.error (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/rollup.js:17911:24)
at emitParsedOptionsErrors (/Users/bgd/Documents/Projects/Essential modules/node_modules/@rollup/plugin-typescript/dist/index.js:310:17)
at Object.buildStart (/Users/bgd/Documents/Projects/Essential modules/node_modules/@rollup/plugin-typescript/dist/index.js:469:13)
at /Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/rollup.js:18109:25
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Promise.all (index 2)
at Object.rollupInternal (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/rollup.js:19099:9)
at Task.run (/Users/bgd/Documents/Projects/Essential modules/node_modules/rollup/dist/shared/watch.js:715:28)
์ค์น๋ Svelte VS Code ํ์ฅ:
์ค์น๋ ๊ธฐํ VS Code ํ์ฅ:
package.json
ํ์ผ:
{
"name": "svelte-app",
"version": "0.0.1",
"scripts": {
"build": "npm install && rollup -c",
"dev": "npm install && rollup -c -w",
"start": "sirv public --single",
"lint": "eslint . --ext .js,.svelte; exit 0",
"lint-report": "eslint . --ext .js,.svelte -o ./.eslint-report.html -f html; exit 0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@rollup/plugin-typescript": "^4.1.2",
"eslint": "^7.2.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-svelte3": "^2.7.3",
"rollup": "^2.15.0",
"rollup-plugin-livereload": "^1.3.0",
"rollup-plugin-svelte": "^5.2.2",
"rollup-plugin-terser": "^6.1.0",
"svelte": "^3.23.1",
"svelte-preprocess": "^3.9.7",
"tslib": "^2.0.0",
"typescript": "^3.9.5"
},
"dependencies": {
"page": "^1.11.6",
"sirv-cli": "^0.4.6"
}
}
rollup.config.js
ํ์ผ:
import svelte from "rollup-plugin-svelte";
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 autoPreprocess from "svelte-preprocess";
import typescript from "@rollup/plugin-typescript";
const production = !process.env.ROLLUP_WATCH;
export default {
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/bundle.js"
},
plugins: [
svelte({
dev: !production,
css: css => {
css.write("public/build/bundle.css");
},
preprocess: autoPreprocess()
}),
resolve({
browser: true,
dedupe: ["svelte"]
}),
commonjs(),
typescript(),
!production && serve(),
!production && livereload("public"),
production && terser()
],
watch: {
clearScreen: false
}
};
function serve () {
let started = false;
return {
writeBundle () {
if (!started) {
started = true;
require("child_process").spawn("npm", ["run", "start", "--", "--dev"], {
stdio: ["ignore", "inherit", "inherit"],
shell: true
});
}
}
};
}
svelte.config.js
ํ์ผ:
const autoPreprocess = require("svelte-preprocess");
module.exports = {
preprocess: [
autoPreprocess()
]
};
@elvtcc ์ ๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๊ทธ๊ฒ์ ํด๊ฒฐํ๊ธฐ ์ํด ๋ค์์ด ์์ต๋๋ค.
main.js
์ด main.ts
rollup.config.json
์์ input: 'src/main.js'
์์ input: 'src/main.ts'
๋ณ๊ฒฝ๋์์ต๋๋ค.tsconfig.json
๋ ์์ด์ผ ํฉ๋๋ค)์๊ณ , dummdidumm์ด entry file (main.js) has still to be a javascript file
๋ผ๊ณ ๋งํ์ง๋ง ์๋ํ์ง ์์ต๋๋ค.
๋งค์ฐ ํฅ๋ฏธ๋กญ์ต๋๋ค. ์ด ์ค์ ์ ์ฌ์ ํ Vodoo๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด์จ๋ ์๋ํ๊ฒ ๋์ด ๊ธฐ์ฉ๋๋ค! ๋๋ ํต์ฌ svelte repo๋ก ๊ฐ์ ๊ฑฐ๊ธฐ์์ ๊ณต์์ ์ธ typescript ํ ํ๋ฆฟ์ ๋ง๋๋ ๊ฒ์ ๋ํด ๋ ผ์ํ ๊ฒ์ ๋๋ค.
@AlexandreCantin @elvtcc
repo๋ฅผ ๋ณด๋ฉด /src
๋๋ ํ ๋ฆฌ( stuff.ts
)์ Typescript ํ์ผ์ด ์๋ค๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.
๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. Typescript์์ ์์ค๋ฅผ ์ฐพ์ ์ ์๋ค๊ณ ๋งํ์ต๋๋ค. ์์์ ์ ์ํ ๋๋ก tsconfig.json
๋ฅผ ์ฌ์ฉํ์ฌ main.ts
๋ก ๋ณ๊ฒฝํ๋ ค๊ณ ์๋ํ์ง๋ง ๋ฒ๋ค ์ฝ๋์์ ์๋ ์์ฑ๋ ์ด์ํ commonjs ๋ชจ๋ ๋ด๋ณด๋ด๊ธฐ exports not found
๋ก ์ธํด ์ค๋จ๋์์ต๋๋ค. ๋ชจ๋ ์คํ์ผ์ด ์ด๊ฒ์ ๊ณ ์น ๊ฒ์
๋๋ค).
์๋ํ๋ ๊ฒ์ /src
(์ํ๋ ๊ฒฝ์ฐ tsconfig.json
์์ด) ์์ empty.ts
(๋๋ ๋ชจ๋ ํ์ผ)์ ๋ง๋ ๋ค์ dev
๋ฅผ ์คํํ๋ ๊ฒ์
๋๋ค.
ํธ์ง: ๋ช ๊ฐ์ง ์คํ ํ ์๋ํ๋ ๋ชจ๋ ์กฐํฉ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
main.js
, tsconfig.json
, .ts
๋ด๋ถ์ ๋จ์ผ /src
main.ts
, ์๋์ tsconfig.json
, ์ฑ ๊ฐ์ ธ์ค๊ธฐ์ ts-ignore
์ถ๊ฐ:ts
// @ts-ignore
import App from './App.svelte'
main.ts
, tsconfig.json
๋ฐ ๋ค์ ์ค ํ๋๋ก ์ค์ :{
"compilerOptions": {
"target": "ES2015 (or greater)",
"module": "ES2015, ES2020, or ESNEXT"
}
}
@GavinRay97 ์กฐ์ฌ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค! ํ ํ๋ฆฟ์ ์ ๋ฐ์ดํธํ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@elvtcc ์ ๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๊ทธ๊ฒ์ ํด๊ฒฐํ๊ธฐ ์ํด ๋ค์์ด ์์ต๋๋ค.
main.js
์ดmain.ts
rollup.config.json
์์input: 'src/main.js'
์์input: 'src/main.ts'
๋ณ๊ฒฝ๋์์ต๋๋ค.(์ฐธ๊ณ :
tsconfig.json
๋ ์์ด์ผ ํฉ๋๋ค)์๊ณ , dummdidumm์ด
entry file (main.js) has still to be a javascript file
๋ผ๊ณ ๋งํ์ง๋ง ์๋ํ์ง ์์ต๋๋ค.