1. ๋ฆฌ์กํธ๋ฅผ ์ฌ์ฉํ๊ณ ์ถ์ ํ๋ก์ ํธ์ ๋๋ ํฐ๋ฆฌ์ ๋ค์ด๊ฐ๋ค.
2. ์๋์ ๋ช ๋ น์ด๋ฅผ ํตํด ๋ ธ๋ ํ๋ก์ ํธ๋ฅผ ์์ฑ-์ด๊ธฐํ ํ๋ฉฐ package.json์ ๋ง๋ ๋ค
npm init -y
3. JSX ์ปดํ์ผ์ ์ํ Babel์ ์ค์นํ๋ค.
npm install --save-dev @babel/core babel-loader @babel/cli @babel/preset-env @babel/preset-react
babel-loader๋ ์นํฉ๊ณผ ๊ฐ์ด ์ฌ์ฉํ๊ธฐ ์ํด ๋ค์ดํด์ค๋ค.
4. Webpack ์ค์น
npm install --save-dev webpack webpack-cli webpack-dev-server
5. htmlWebpackPlugin ์ค์น
npm install --save-dev html-webpack-plugin
6. react, react-dom ์ค์น
npm install react react-dom
7. ํ๋ก์ ํธ ํด๋ ์์ babel.lrcํ์ผ์ ๋ง๋ค๊ณ ์๋ ์ฝ๋๋ฅผ ๋ฃ์ด์ค๋ค.
{
"presets": [
"@babel/preset-env",
["@babel/preset-react", { "runtime": "automatic" }]
]
}
"runtime":"automatic" ์ผ๋ก ๋ฐ๊พผ๋ค. ์ต์ jsx-transform ๊ธฐ๋ฅ์ ์ด์ฉํ ์ ์๋๋ก ํ ๊ฒ์ด๋ค. ์๋ ๋งํฌ ์ถ๊ฐ ์ค๋ช
https://ko.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
Introducing the New JSX Transform โ React Blog
Although React 17 doesnโt contain new features, it will provide support for a new version of the JSX transform. In this post, we will describe what it is and how to try it. Whatโs a JSX Transform? Browsers donโt understand JSX out of the box, so most
ko.reactjs.org
8. webpack.config.jsํ์ผ์ ํ๋ก์ ํธ ํด๋ ๋ด์ ๋ง๋ค๊ณ ์๋์ ๊ฐ์ด ์ถ๊ฐํ๋ค.
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
entry: './index.js',
mode: 'development',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js',
},
target: 'web',
devServer: {
port: '5000',
static: {
directory: path.join(__dirname, 'public')
},
open: true,
hot: true,
liveReload: true,
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'public', 'index.html')
})
]
};
9. package.json์ ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐํ๋ค.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server .",
"build": "webpack ."
},
10. file loader ์ค์น ํ webpack.config.js์ ์๋์ ์ค์ ์ ์ถ๊ฐํ๋ค.
{
test: /\.(png|jpe?g|gif|svg|webp)$/,
use: ["file-loader"],
},
11. css loader/style loader ์ค์นํ webpack.config.js ์ ์๋์ ์ค์ ์ ์ถ๊ฐํ๋ค.
$ npm install --save-dev style-loader css-loader
module.exports = {
module: {
rules: [
// CSS ํ์ผ ๋ก๋ ์ค์
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
}
}
'react' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] ๋ฐฐ์ด ๋ ๋๋ง ์ ์ฃผ์์ฌํญ (0) | 2023.07.08 |
---|---|
[๋ฆฌ์กํธ๋ฅผ ๋๋์ฒด ์ ์ฐ๋๊ฐ!] React ์ฐ๋ ์ด์ ์ ๋ถ ์์๋ณด๊ธฐ (0) | 2023.07.06 |
[๋ฆฌ์กํธ ์ ๋ก์ด ๊ฐ์ ์ ๋ฆฌ0] ๋ด๊ฐ ์ ๋ก์ด ๋ฆฌ์กํธ ๊ฐ์๋ฅผ ์ ํํ ์ด์ (1) | 2023.07.06 |
[React] Create-React-App ํ๋ก์ ํธ ์ธํ ํ๋ ๋ฐฉ๋ฒ (0) | 2023.03.29 |
[react] github pages๋ก ํ๋ก์ ํธ deployํ๊ธฐ!! (0) | 2023.02.27 |
1. ๋ฆฌ์กํธ๋ฅผ ์ฌ์ฉํ๊ณ ์ถ์ ํ๋ก์ ํธ์ ๋๋ ํฐ๋ฆฌ์ ๋ค์ด๊ฐ๋ค.
2. ์๋์ ๋ช ๋ น์ด๋ฅผ ํตํด ๋ ธ๋ ํ๋ก์ ํธ๋ฅผ ์์ฑ-์ด๊ธฐํ ํ๋ฉฐ package.json์ ๋ง๋ ๋ค
npm init -y
3. JSX ์ปดํ์ผ์ ์ํ Babel์ ์ค์นํ๋ค.
npm install --save-dev @babel/core babel-loader @babel/cli @babel/preset-env @babel/preset-react
babel-loader๋ ์นํฉ๊ณผ ๊ฐ์ด ์ฌ์ฉํ๊ธฐ ์ํด ๋ค์ดํด์ค๋ค.
4. Webpack ์ค์น
npm install --save-dev webpack webpack-cli webpack-dev-server
5. htmlWebpackPlugin ์ค์น
npm install --save-dev html-webpack-plugin
6. react, react-dom ์ค์น
npm install react react-dom
7. ํ๋ก์ ํธ ํด๋ ์์ babel.lrcํ์ผ์ ๋ง๋ค๊ณ ์๋ ์ฝ๋๋ฅผ ๋ฃ์ด์ค๋ค.
{
"presets": [
"@babel/preset-env",
["@babel/preset-react", { "runtime": "automatic" }]
]
}
"runtime":"automatic" ์ผ๋ก ๋ฐ๊พผ๋ค. ์ต์ jsx-transform ๊ธฐ๋ฅ์ ์ด์ฉํ ์ ์๋๋ก ํ ๊ฒ์ด๋ค. ์๋ ๋งํฌ ์ถ๊ฐ ์ค๋ช
https://ko.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
Introducing the New JSX Transform โ React Blog
Although React 17 doesnโt contain new features, it will provide support for a new version of the JSX transform. In this post, we will describe what it is and how to try it. Whatโs a JSX Transform? Browsers donโt understand JSX out of the box, so most
ko.reactjs.org
8. webpack.config.jsํ์ผ์ ํ๋ก์ ํธ ํด๋ ๋ด์ ๋ง๋ค๊ณ ์๋์ ๊ฐ์ด ์ถ๊ฐํ๋ค.
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
entry: './index.js',
mode: 'development',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js',
},
target: 'web',
devServer: {
port: '5000',
static: {
directory: path.join(__dirname, 'public')
},
open: true,
hot: true,
liveReload: true,
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'public', 'index.html')
})
]
};
9. package.json์ ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐํ๋ค.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server .",
"build": "webpack ."
},
10. file loader ์ค์น ํ webpack.config.js์ ์๋์ ์ค์ ์ ์ถ๊ฐํ๋ค.
{
test: /\.(png|jpe?g|gif|svg|webp)$/,
use: ["file-loader"],
},
11. css loader/style loader ์ค์นํ webpack.config.js ์ ์๋์ ์ค์ ์ ์ถ๊ฐํ๋ค.
$ npm install --save-dev style-loader css-loader
module.exports = {
module: {
rules: [
// CSS ํ์ผ ๋ก๋ ์ค์
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
}
}
'react' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] ๋ฐฐ์ด ๋ ๋๋ง ์ ์ฃผ์์ฌํญ (0) | 2023.07.08 |
---|---|
[๋ฆฌ์กํธ๋ฅผ ๋๋์ฒด ์ ์ฐ๋๊ฐ!] React ์ฐ๋ ์ด์ ์ ๋ถ ์์๋ณด๊ธฐ (0) | 2023.07.06 |
[๋ฆฌ์กํธ ์ ๋ก์ด ๊ฐ์ ์ ๋ฆฌ0] ๋ด๊ฐ ์ ๋ก์ด ๋ฆฌ์กํธ ๊ฐ์๋ฅผ ์ ํํ ์ด์ (1) | 2023.07.06 |
[React] Create-React-App ํ๋ก์ ํธ ์ธํ ํ๋ ๋ฐฉ๋ฒ (0) | 2023.03.29 |
[react] github pages๋ก ํ๋ก์ ํธ deployํ๊ธฐ!! (0) | 2023.02.27 |