Jieunny์ ๋ธ๋ก๊ทธ
S4) Unit 3. [์ค์ต] ๊ฐ๋จํ ์น์ฑ ๋ฒ๋ค๋ง ํ ๋ฐฐํฌํ๊ธฐ ๋ณธ๋ฌธ
S4) Unit 3. [์ค์ต] ๊ฐ๋จํ ์น์ฑ ๋ฒ๋ค๋ง ํ ๋ฐฐํฌํ๊ธฐ
Jieunny 2023. 3. 20. 11:45๐ฃ ๋๋ง์ ์๊ณ ๋ผ์คํ ์ด์ธ ๋ฒ๋ค๋ง ํ๊ธฐ
์๋ฒ๋ ์ด๋ป๊ฒ ์ฐ๊ฒฐํ์ง..
์๋ ์๋ฒ ์์ผ๋ ๋ฐ์ดํฐ๊ฐ ๊ทธ๋๋ก ๋จ๋๋ฐ ์ React๋ก ํ๊ฑด ์๋๋๊ฑฐ์ง..!!
๐ญ. ํ์ฌ ๋๋ ํ ๋ฆฌ์ npm ์ค์นํ๊ธฐ
npm init -y
โฐ package.json ํ์ผ ์์ฑ
๐ฎ. ์นํฉ ์ค์นํ๊ธฐ
npm install -D webpack webpack-cli
๐ฏ. Webpack.config.js ํ์ผ ์์ฑํ๊ธฐ
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'app.bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
โฐ ๊ฒฝ๋ก๊ฐ src/index.js๋ก ๋์ด์๊ธฐ ๋๋ฌธ์ srcํด๋ ์์ฑํด์ html, js, cssํ์ผ์ ๋ชจ๋ src ํด๋ ๋ฐ์ผ๋ก ์ฎ๊ฒจ์ค๋ค.
๐ฐ. jsํ์ผ ๋ฒ๋ค๋งํ๊ธฐ
npx webpack
"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
โฐ package.json์ ์ด๋ ๊ฒ ์ค์ ํด๋์ผ๋ฉด npm run build๋ก ์ฝ๊ฒ ๋ฒ๋ค๋ง ํ ์ ์๋ค.
โฐ ์ฑ๊ณตํ๋ฉด dist ํด๋์ app.bundle.js๊ฐ ์์ฑ๋๋ค.
๐ฑ. htmlํ์ผ ๋ฒ๋ค๋งํ๊ธฐ
1๏ธโฃ html-webpack-plugin ์ค์นํ๊ธฐ
npm i -D html-webpack-plugin
2๏ธโฃ webpack.config.js ํ์ผ์ ํด๋น ํ๋ฌ๊ทธ์ธ ๋ฑ๋กํ๊ธฐ
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: 'app.bundle.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
}),
],
};
3๏ธโฃ npm run build๋ก ๋ฒ๋ค๋งํ๊ธฐ
โฐ ์ฑ๊ณตํ๋ฉด dist ํด๋์ index.html์ด ์์ฑ๋๋ค.
โฐ css๋ ์ ์ฉ๋์ง ์์์ง๋ง index.html ํ์ผ์ ์ ์์ ์ผ๋ก ์คํ๋์ด์ผ ํ๋ค.
๐ฒ. cssํ์ผ ๋ฒ๋ค๋งํ๊ธฐ
1๏ธโฃ style-loader ์ css-loader ์ค์นํ๊ธฐ
npm i -D style-loader css-loader
2๏ธโฃ index.js ํ์ผ์์ CSS ํ์ผ ์ํฌํธ ํ๊ธฐ
import './style.css";
โฐ index.jsํ์ผ์ ๊ธฐ์ค์ผ๋ก cssํ์ผ์ ํจ๊ป ๋ฌถ์ด์ฃผ๋ ๊ฐ๋ ์ด๊ธฐ๋๋ฌธ์ cssํ์ผ๊ณผ์ ์ฐ๊ฒฐ ๊ด๊ณ๋ jsํ์ผ์ ๋ช ์๋์ด์ผ ํ๋ค.
3๏ธโฃ webpack.config.js์ ์ค์นํ ๋ก๋ ๋ฑ๋ก
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: 'app.bundle.js',
path: path.resolve(__dirname, 'dist'),
},
module : {
rules: {
test: /\.css$/,
use: ["style-loader", "css-loader"],
exclude: /node_modules/,
}
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
}),
],
};
โฐ test ํญ๋ชฉ์ ์ ์๋ ์ ๊ท์์ ๋งค์นญ๋๋ ํ์ผ(.css ํ์ผ)์ use ํญ๋ชฉ์ ๋ฑ๋ก๋ ๋ก๋๋ฅผ ํตํด์ ์ฒ๋ฆฌ๋๋ค.
โฐ ๋ก๋๋ css-loader๊ฐ ๋จผ์ ์ ์ฉ๋๊ณ , styled-loader๊ฐ ์ ์ฉ๋๋ค.
4๏ธโฃ npm run build๋ก ๋ฒ๋ค๋งํ๊ธฐ
โฐ index.html ํ์ผ์ ์ด๋ฉด css๊ฐ ์ ์ฉ๋์ด ์์ด์ผ ํ๋ค.
๐ฒ. ์ด๋ฏธ์ง ํ์ผ ๋ถ๋ฌ์ค๊ธฐ
โฐ ์ด๋ฏธ์ง๋ fileloader๋ฅผ ์ฌ์ฉํด์ ๋ถ๋ฌ์์ผ ํ๋ค.
1๏ธโฃ file loader ์ค์นํ๊ธฐ
npm i file-loader -D
2๏ธโฃ webpack.config.js์ ์ค์ ์ถ๊ฐํด์ฃผ๊ธฐ
{
test: /\.jpeg$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]'
// ์ด๋ฆ์ด ๋๋คํ ํด์๊ฐ์ผ๋ก ์์ฑ๋๋ ๊ฒ์ ๋ง๊ธฐ ์ํด ์ด๋ฆ์ ๋ฐ๋ก ์ค์ ํด์ค๋ค.
}
},
],
},
3๏ธโฃ index.js์ ์ด๋ฏธ์ง ํ์ผ ์ํฌํธํ๊ธฐ
import './images/cinnamon.jpeg';
import './images/๊ณํผ_.jpeg';
import './images/tab.jpeg';
โฐ ์ด๋ฏธ์ง๋ ์ ํํ ์ด๋ฆ์ผ๋ก ๋ถ๋ฌ์์ง๋ค.
๐ฃ ๋ฒ๋ค๋ง ํ Github์ ๋ฐฐํฌํ๊ธฐ
1๏ธโฃ webpack.config.js ์์ output์ dist์์ docs๋ก ๋ฐ๊ฟ์ค๋ค.
2๏ธโฃ ์ด๋ฏธ ๋ฒ๋ค๋ง๋ distํ์ผ์ด๋ฆ์ docs๋ก ๋ฐ๊พผ๋ค.(๊นํ ํ์ด์ง ๋ฐฐํฌ๊ฐ ๋ชฉํ๋ผ๋ฉด ์ ์ด์ output์ docs๋ก ์ค์ ํ๊ณ ์ ์ฅํ์)
3๏ธโฃ ๋น๋๋ฅผ ๋ค ๋ง์น๊ณ git push๋ฅผ ์คํํ๋ค.
4๏ธโฃ ํ์ฌ ์์ ์ค์ธ ๊นํ ๋ฆฌํฌ์งํ ๋ฆฌ์ setting- pages์์ source ์ต์ ์ ํ์ฌ ๋ธ๋์น, root๋ฅผ /docs ํด๋๋ก ์ค์ ํ๊ณ ์ ์ฅํ๋ค.
๐ ๋ฐฐํฌ ๋งํฌ
https://jieuny0314.github.io/fe-sprint-my-agora-states/
My Agora States
jieuny0314.github.io
'CodeStates > Training' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
S4) Unit 4. [์ค์ต] Custom Hook (0) | 2023.03.24 |
---|---|
S4) Unit 3. [์ค์ต] ๋ฆฌ์กํธ ์น์ฑ ๋ฒ๋ค๋ง ํ ๋ฐฐํฌํ๊ธฐ (0) | 2023.03.21 |
S4) Unit 2. [์ค์ต] ๋ฐ์ํ ์น ๊ตฌํํ๊ธฐ (0) | 2023.03.17 |
S4) Unit 1. [์ค์ต] Tree & Graph ๋ฌธ์ (0) | 2023.03.15 |
S4) Unit 1. [์ค์ต] Stack & Queue ๋ฌธ์ (0) | 2023.03.14 |