{"id":12874,"date":"2022-10-04T09:02:35","date_gmt":"2022-10-04T00:02:35","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=12874"},"modified":"2022-12-18T14:57:44","modified_gmt":"2022-12-18T05:57:44","slug":"webpack-typescript%eb%a5%bc-%ec%9d%b4%ec%9a%a9%ed%95%9c-%ec%9b%b9%ed%8e%98%ec%9d%b4%ec%a7%80-%ea%b0%9c%eb%b0%9c-%ec%84%a4%ec%a0%95","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=12874","title":{"rendered":"Webpack, TypeScript\ub97c \uc774\uc6a9\ud55c \uc6f9\ud398\uc774\uc9c0 \uac1c\ubc1c \uc124\uc815"},"content":{"rendered":"<h2>\uae30\ubcf8 \uc124\uc815<\/h2>\n<h4># Node.js \uc124\uce58<\/h4>\n<p>npm \uba85\ub839 \uc2e4\ud589\uc744 \uc704\ud568<\/p>\n<h4># <code>npm init -y<\/code><\/h4>\n<p>npm init\ub294 package.json\uc744 \ub9cc\ub4e4\uae30 \uc704\ud55c \uba85\ub839\uc774\uace0 -y\ub97c \ubd99\uc784\uc73c\ub85c\uc368 \ubcc4\ub3c4\uc758 \uc785\ub825 \uc5c6\uc774 \uae30\ubcf8 \uac12\uc73c\ub85c \uc9c4\ud589 \uc2dc\ud0b4. package.json\uc740 \uc791\uc131\ud558\uace0\uc790 \ud558\ub294 \ud504\ub85c\uc81d\ud2b8\uc5d0 \ub300\ud55c \uc124\uc815 \ud30c\uc77c\ub85c \ubcfc \uc218 \uc788\uc73c\uba70, \ud504\ub85c\uc81d\ud2b8 \uc774\ub984\uacfc \ubc84\uc804 \ub4f1\uacfc \uac19\uc740 \uc124\uba85\uacfc \ud504\ub85c\uc81d\ud2b8\uac00 \uc0ac\uc6a9\ud558\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc5d0 \ub300\ud55c \uc815\ubcf4 \uadf8\ub9ac\uace0 \ud504\ub85c\uc81d\ud2b8 \uc2e4\ud589 \ub4f1\uc744 \uc704\ud55c \uba85\ub839\uc5d0 \ub300\ud55c \uc815\ubcf4\uac00 \ub2f4\uaca8\uc788\uc74c. package.json \ud30c\uc77c\uc740 npm\uc744 \uc704\ud55c \ud30c\uc77c\uc784(VS.Code\ub97c \uc704\ud55c \uac83\uc774 \uc544\ub2d8)<\/p>\n<h4># <code>npm install webpack webpack-cli --save-dev<\/code><\/h4>\n<h4># <code>npm install typescript ts-loader --save-dev<\/code><\/h4>\n<h4># tsconfig.json \ud30c\uc77c \uc0dd\uc131 \ubc0f \ub0b4\uc6a9 \uc791\uc131<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n    \"compilerOptions\": {\r\n        \"outDir\": \".\/dist\/\",\r\n        \"sourceMap\": true,\r\n        \"noImplicitAny\": true,\r\n        \"module\": \"es6\",\r\n        \"target\": \"es5\",\r\n        \"allowJs\": true\r\n    }\r\n}\r\n<\/pre>\n<h4># webpack.config.js \ud30c\uc77c \uc0dd\uc131 \ubc0f \ub0b4\uc6a9 \uc791\uc131<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\nconst path = require(\"path\");\r\n\r\nmodule.exports = {\r\n    mode: \"development\",\r\n    entry: \".\/src\/index.ts\",\r\n    devtool: \"inline-source-map\",\r\n    module: {\r\n        rules: [\r\n            {\r\n                test: \/\\.tsx?$\/,\r\n                use: \"ts-loader\",\r\n                exclude: \/node_modules\/,\r\n            },\r\n        ],\r\n    },\r\n    resolve: {\r\n        extensions: [\".tsx\", \".ts\", \".js\"],\r\n    },\r\n    output: {\r\n        filename: \"bundle.js\",\r\n        path: path.resolve(__dirname, \"dist\"),\r\n    },\r\n}\r\n<\/pre>\n<h4># src, dist \ud3f4\ub354 \ubc0f index.html(dist \ud3f4\ub354), index.ts(src \ud3f4\ub354) \ud30c\uc77c \uc0dd\uc131<\/h4>\n<h4># index.html \ucf54\ub4dc \uc785\ub825<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">\r\n...\r\n\r\n&lt;script src=\"bundle.js\">&lt;\/script> \r\n\r\n...\r\n<\/pre>\n<h4># index.ts \ucf54\ub4dc \uc785\ub825<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"typescript\">\r\nconsole.log(\"Hello\");\r\n<\/pre>\n<h4># package.json \ud30c\uc77c\uc758 &#8220;scripts&#8221; \ud30c\ud2b8\uc5d0 &#8220;bundle&#8221;: &#8220;webpack&#8221; \uc785\ub825<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n  ..\r\n  \"scripts\": {\r\n    ..\r\n    \"bundle\": \"webpack\"\r\n  },\r\n  ..\r\n}\r\n<\/pre>\n<h4># <code>npm run bundle<\/code> \uc2e4\ud589<\/h4>\n<p>Typescript\ub85c \uc791\uc131\ub41c \ud30c\uc77c\uc744 Javascript \ud30c\uc77c\ub85c \ud2b8\ub79c\uc2a4\ud30c\uc77c\ub9c1 \uc2dc\ud0b4<\/p>\n<h2>\uc790\ub3d9 \uc2e4\ud589\uc744 \uc704\ud55c \uc124\uc815<\/h2>\n<h4># package.json \ud30c\uc77c\uc758 &#8220;scripts&#8221; \ud30c\ud2b8\uc5d0 &#8220;watch&#8221;: &#8220;webpack &#8211;watch&#8221; \ubc0f &#8220;start&#8221;: &#8220;npm run bundle &#038;&#038; npm run watch&#8221; \ucd94\uac00<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n  ..\r\n  \"scripts\": {\r\n    ..\r\n    \"bundle\": \"webpack\",\r\n    \"watch\": \"webpack --watch\",\r\n    \"start\": \"npm run bundle && npm run watch\"\r\n  },\r\n  ..\r\n}\r\n<\/pre>\n<h4># VS.Code\uc5d0\uc11c Live Server \ud655\uc7a5 \uae30\ub2a5 \uc124\uce58<\/h4>\n<h4># <code>npm start<\/code> \uc2e4\ud589<\/h4>\n<p>\uc774\uc81c\ubd80\ud130 Typescript\ub85c \uc791\uc131\ub41c \ud30c\uc77c\uc744 \uc218\uc815\ud558\uba74 Javascript \ud30c\uc77c\ub85c \uc9c0\ub3d9\uc73c\ub85c \ud2b8\ub79c\uc2a4\ud30c\uc77c\ub9c1 \uc2dc\ud0b4 <\/p>\n<h4># index.html \uc5f4\uace0 GO LIVE \ud65c\uc131\ud654<\/h4>\n<h2>\ube0c\ub808\uc774\ud06c \ub514\ubc84\uae45<\/h2>\n<h4># VS.Code\uc758 &#8220;\uc2e4\ud589 \ubc0f \ub514\ubc84\uadf8&#8221; \ud074\ub9ad\uc744 \ud1b5\ud574 launch.json\uc744 \uc0dd\uc131 (\ud06c\ub86c \uc120\ud0dd)<\/h4>\n<h4># launch.json \ud30c\uc77c\uc5d0\uc11c &#8220;url&#8221;\uc758 \uac12\uc744 &#8220;http:\/\/127.0.0.1:5500\/dist&#8221;\uc73c\ub85c \uc218\uc815<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n    ..\r\n    \"configurations\": [\r\n        {\r\n            ..\r\n            \"url\": \"http:\/\/127.0.0.1:5500\/dist\",\r\n            ..\r\n        }\r\n    ]\r\n}\r\n<\/pre>\n<h2>babylonjs \ub77c\uc774\ube0c\ub7ec\ub9ac \uc124\uce58<\/h2>\n<h4># npm install @babylonjs\/core<\/h4>\n<h4># tsconfig.json\uc5d0 &#8220;moduleResolution&#8221;: &#8220;node&#8221; \ucd94\uac00<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n    \"compilerOptions\": {\r\n       ..\r\n       \"moduleResolution\": \"node\"\r\n    }\r\n}\r\n<\/pre>\n<p>\uc704\uc758 \uc124\uc815\uc744 \uc785\ub825\ud574\uc57c babylonjs \ubaa8\ub4c8\uc744 import\ud560 \ub54c(\uc608: import { Scene } from &#8220;@babylonjs\/core&#8221;) \ubb38\uc81c\uac00 \uc5c6\uc74c<\/p>\n<h2>\ucd5c\uc885 \uc124\uc815 \ud30c\uc77c \ub0b4\uc6a9<\/h2>\n<h4># tsfonfig.json<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n    \"compilerOptions\": {\r\n        \"outDir\": \".\/dist\/\",\r\n        \"sourceMap\": true,\r\n        \"noImplicitAny\": true,\r\n        \"module\": \"es6\",\r\n        \"target\": \"es5\",\r\n        \"allowJs\": true,\r\n\r\n        \"moduleResolution\": \"node\"\r\n    }\r\n}\r\n<\/pre>\n<h4># webpack.config.js<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\nconst path = require(\"path\");\r\n\r\nmodule.exports = {\r\n    mode: \"development\",\r\n    entry: \".\/src\/index.ts\",\r\n    devtool: \"inline-source-map\",\r\n    module: {\r\n        rules: [\r\n            {\r\n                test: \/\\.tsx?$\/,\r\n                use: \"ts-loader\",\r\n                exclude: \/node_modules\/\r\n            },\r\n        ],\r\n    },\r\n    resolve: {\r\n        extensions: [\".tsx\", \".ts\", \".js\"],\r\n    },\r\n    output: {\r\n        filename: \"bundle.js\",\r\n        path: path.resolve(__dirname, \"dist\"),\r\n    },\r\n}\r\n<\/pre>\n<h4># package.json<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n  \"name\": \"tstbabylonjs_ts\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"\",\r\n  \"main\": \"index.js\",\r\n  \"scripts\": {\r\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\",\r\n    \"bundle\": \"webpack\",\r\n    \"watch\": \"webpack --watch\",\r\n    \"start\": \"npm run bundle && npm run watch\"\r\n  },\r\n  \"keywords\": [],\r\n  \"author\": \"\",\r\n  \"license\": \"ISC\",\r\n  \"devDependencies\": {\r\n    \"ts-loader\": \"^9.4.1\",\r\n    \"typescript\": \"^4.8.4\",\r\n    \"webpack\": \"^5.74.0\",\r\n    \"webpack-cli\": \"^4.10.0\"\r\n  },\r\n  \"dependencies\": {\r\n    \"@babylonjs\/core\": \"^5.26.1\"\r\n  }\r\n}\r\n<\/pre>\n<h4># launch.json<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n{\r\n    \/\/ IntelliSense\ub97c \uc0ac\uc6a9\ud558\uc5ec \uac00\ub2a5\ud55c \ud2b9\uc131\uc5d0 \ub300\ud574 \uc54c\uc544\ubcf4\uc138\uc694.\r\n    \/\/ \uae30\uc874 \ud2b9\uc131\uc5d0 \ub300\ud55c \uc124\uba85\uc744 \ubcf4\ub824\uba74 \uac00\ub9ac\ud0b5\ub2c8\ub2e4.\r\n    \/\/ \uc790\uc138\ud55c \ub0b4\uc6a9\uc744 \ubcf4\ub824\uba74 https:\/\/go.microsoft.com\/fwlink\/?linkid=830387\uc744(\ub97c) \ubc29\ubb38\ud558\uc138\uc694.\r\n    \"version\": \"0.2.0\",\r\n    \"configurations\": [\r\n        {\r\n            \"type\": \"chrome\",\r\n            \"request\": \"launch\",\r\n            \"name\": \"Launch Chrome against localhost\",\r\n            \"url\": \"http:\/\/127.0.0.1:5500\/dist\",\r\n            \"webRoot\": \"${workspaceFolder}\"\r\n        }\r\n    ]\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uae30\ubcf8 \uc124\uc815 # Node.js \uc124\uce58 npm \uba85\ub839 \uc2e4\ud589\uc744 \uc704\ud568 # npm init -y npm init\ub294 package.json\uc744 \ub9cc\ub4e4\uae30 \uc704\ud55c \uba85\ub839\uc774\uace0 -y\ub97c \ubd99\uc784\uc73c\ub85c\uc368 \ubcc4\ub3c4\uc758 \uc785\ub825 \uc5c6\uc774 \uae30\ubcf8 \uac12\uc73c\ub85c \uc9c4\ud589 \uc2dc\ud0b4. package.json\uc740 \uc791\uc131\ud558\uace0\uc790 \ud558\ub294 \ud504\ub85c\uc81d\ud2b8\uc5d0 \ub300\ud55c \uc124\uc815 \ud30c\uc77c\ub85c \ubcfc \uc218 \uc788\uc73c\uba70, \ud504\ub85c\uc81d\ud2b8 \uc774\ub984\uacfc \ubc84\uc804 \ub4f1\uacfc \uac19\uc740 \uc124\uba85\uacfc \ud504\ub85c\uc81d\ud2b8\uac00 \uc0ac\uc6a9\ud558\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc5d0 \ub300\ud55c \uc815\ubcf4 \uadf8\ub9ac\uace0 \ud504\ub85c\uc81d\ud2b8 \uc2e4\ud589 \ub4f1\uc744 \uc704\ud55c \uba85\ub839\uc5d0 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=12874\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Webpack, TypeScript\ub97c \uc774\uc6a9\ud55c \uc6f9\ud398\uc774\uc9c0 \uac1c\ubc1c \uc124\uc815&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88],"tags":[],"class_list":["post-12874","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/12874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12874"}],"version-history":[{"count":15,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/12874\/revisions"}],"predecessor-version":[{"id":13268,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/12874\/revisions\/13268"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12874"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}