- 프로젝트 생성 및 깃 저장소 master 푸시.
mkdir react-webpack
yarn init -y
git inithttps://gitignore.io 로 .gitignore 생성
.gitignore
# Created by https://www.gitignore.io/api/node,react,macos,visualstudiocode
# Edit at https://www.gitignore.io/?templates=node,react,macos,visualstudiocode
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# react / gatsby
public/
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
### react ###
.DS_*
**/*.backup.*
**/*.back.*
node_modules
bower_componets
*.sublime*
psd
thumb
sketch
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
# End of https://www.gitignore.io/api/node,react,macos,visualstudiocode
git remote add origin https://github.com/yungblud/react-webpack
git add .
git commit -m "init"
git push origin master- 프로젝트 구조 설정 및 기초가 되는 node module 인스톨
- src 폴더 생성.
- public 폴더 생성.
- es6 문법을 사용하기 위한 노드 모듈 설치.
yarn add -D @babel/core @babel/preset-env @babel/preset-react- 웹팩 관련 모듈 설치
yarn add -D webpack webpack-cli webpack-dev-server babel-loader css-loader style-loader html-webpack-plugin- webpack.config.js 설정
webpack.config.js 파일 생성
webpack.config.js
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const htmlPlugin = new HtmlWebpackPlugin({
template: './public/index.html',
filename: './index.html',
})
const isDevelopMode = process.env.NODE_ENV === 'development'
module.exports = {
entry: './src/index.js',
output: {
path: path.join(__dirname, '/build'),
filename: 'index.bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(css)$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: {
localIdentName: isDevelopMode
? '[path][name]__[local]--[hash:base64:5]'
: '[name]__[local]--[hash:base64:5]',
},
importLoaders: 1,
sourceMap: true,
},
},
],
},
],
},
plugins: [htmlPlugin],
}기본적인 리액트를 웹팩으로 띄울수 있는 설정만 하였다.
- public 폴더에 index.html 생성
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>React PWA Webpack</title>
</head>
<body>
<div id="root"></div>
</body>
</html>id 를 root로 하는 태그생성.