*Setup Webpack and Babel for React를 참고하였습니다.
(https://www.youtube.com/watch?v=ydDUm1yPZs0)
dependencies
react
react-dom
devDependencies
webpack
webpack-cli
webpack-dev-server
@babel/core
@babel/preset-env
@babel/preset-react
babel-loader
style-loader
sass-loader
node-sass
1.webpack.config.js
const path = require("path")
module.exports = {
entry: "./src/index.js",
output: {
path: path.join(__dirname, "public"),
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.scss$/,
use: ["style-loader", "sass-loader"]
}
]
},
devtool: "cheap-module-eval-source-map",
devServer: {
contentBase: path.join(__dirname, "public"),
port: 9000,
},
}
2.Public
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script src="./bundle.js"></script>
</body>
</html>
styles.scss
$bg-color: #333;
$text-color: #fff;
* {
background-color: $bg-color;
color: $text-color
h1 {
color: red
}
}
.babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
index.js
import React from "react";
import reactDOM from "react-dom";
import "./styles/style.scss"
const App = () => {
return <h1>Hello from react</h1>
}
reactDOM.render(<App/>, document.getElementById("root"))
controlled component vs uncontrolled component (0) | 2020.08.10 |
---|---|
class component vs functional component (0) | 2020.08.10 |
Props (0) | 2020.08.09 |
React (0) | 2020.08.09 |
JSX (0) | 2020.08.09 |