1ํธ์ ๋์ณค๋ค๋ฉด ๊ผญ ๋ณด๊ณ ์ค์!
์ํ๋ ๊ณณ์ ํ๋ก์ ํธ ํด๋๋ฅผ ๋ง๋ ํ dist/index.html
, src/index.js
๋ฅผ ํ๋์ฉ ๋ง๋ค์ด์ค๋ค.
ํ์ผ ๊ตฌ์กฐ๋ ๋ค์๊ณผ ๊ฐ๋ค.
.
โโโ dist
โ โโโ index.html
โโโ src
โ โโโ index.js
โโโ README.md
index.js
๋ ๋์ค์ ์์ ํ๊ณ , ์ผ๋จ index.html
์ ๋ค์ด๊ฐ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํด์ฃผ์.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Firebase-9-Demo</title>
<script src="bundle.js" defer></script>
</head>
<body>
<h1>Firebase๐ฅ<h1>
</body>
</html>
<script>
ํ๊ทธ ์์ bundle.js
๋ผ๋ ํ์ผ์ ๋์ค์ ์ค์ ํ webpack์ด ์์ฑํด์ค๋ค.
ํน์ ์ฃผ์๋ก ๋ค์ด๊ฐ์ ๋, ์ด html ํ์ด์ง๋ฅผ ๋ณด๋๊ฒ ์ฐ๋ฆฌ์ ๋ชฉํ๋ค.
Node.js๊ฐ ์ค์น๋์ด ์๋จ ๊ฐ์ ํ์ npm command๋ฅผ ์ธ ์ ์๋ค.
npm init
์คํํ๋ฉด, package.json
๊ฐ ์์ฑ๋๋ค.
์์ผ๋ก npm run build
๋ก webpack์ ์คํํ ์์ ์ด๋ฏ๋ก package.json
์ ์์ ํด์ค์ผ ํ๋ค.
scripts
๋ผ๊ณ ๋์ด ์๋ ๋ถ๋ถ์ โbuildโ: โwebpackโ
์ ์ถ๊ฐํด์ฃผ์.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
npm i webpack webpack-cli -D
-D
์ต์
: Development Dependency์ ์ถ๊ฐ
์ ์ฝ๋๋ฅผ ์คํํด webpack์ ์ค์นํ๋ค. Firebase ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์์ ์ฐ๋ฆฌ๊ฐ importํด์ ์ฐ๋ ๋ชจ๋๋ง output file์ ๋ฒ๋ค๋ง ํด์ฃผ๋ ์ญํ ์ ํ ๊ฑฐ๋ค.
์ค์น ํ, ํ๋ก์ ํธ์ root folder์ webpack.config.js
๋ ํ์ผ์ ๋ง๋ ๋ค.
์์๋ ๋ค์๊ณผ ๊ฐ์ด ์ ์ด์ค๋ค.
const path = require("path");
module.exports = {
mode: "development",
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
},
watch: true,
};
์์ธํ ์ค๋ช
์ ์๋ตํ๊ฒ ์ง๋ง, entry
์ ํ์ผ์ ํตํด ์ฐ๊ฒฐ๋ ๋ชจ๋ ํ์ผ๋ค์ ouput
์ ๋ฐ๋ผ ์ฐ๋ฆฌ๊ฐ HTML์ ์ถ๊ฐํ๋ bundle.js
๋ฅผ ๋ง๋ค์ด์ค๋ค๋ ๋ป์ด๋ค. npm, webpack ๋ฑ์ ๋ํด์๋ ๋ ์ ๋ฆฌ๋ฅผ ํด์ ์ฌ๋ฆด ์๊ฐ์ด๋ค.
์ฐธ๊ณ ๋ก watch: true
๋ webpack์ด ์ง์ผ๋ณด๊ณ ์๋ค๊ฐ ํ์ผ์ ๋ณ๊ฒฝ์ด ์๊ธฐ๋ฉด ๋ค์ ๋ฒ๋ค๋งํด์ค๋ค๋ ๋ป์ด๋ค.
๐ฅ๋ค์์๋ firebase๋ฅผ ์ค์นํ๊ณ deploy๊น์ง ํด๋ณด์!