루트폴더에 npm init을 해준다.
*이때 폴더에 package.json파일이 생겨남
웹팩과 바벨을 설치해준다
*웹팩 바벨은 개발모드에서만 사용
npm i -D webpack
npm i -D webpack-cli
npm i -D @babel/core
npm i -D @babel/preset-env
npm i -D @babel/preset-react
npm i -D babel-loader
const {webpack} = require('webpack');
module.exports ={
name : '',
mode : '',
devtool : '',
entry : {
},
module : {
},
output : {
}
}
npm i -D @pmmmwh/react-refresh-webpack-plugin
npm webpack-dev-server
const path = require('path');
const webpackRefresh = require('@pmmmwh/react-refresh-webpack-plugin');
const { webpack } = require('webpack');
module.exports = {
name : 'reactStudy',
mode : 'development',
devtool : 'eval',
resolve : {
extensions : ['.js', '.jsx']
},
// 입력
entry : {
app : ['./client.jsx'],
},
// 룰 -> loaders라고함
module: {
rules: [{
test : /\.jsx?/,
loader : 'babel-loader',
options : {
presets : [
['@babel/preset-env', {
targets : {
browsers : ['> 0.1% in KR', 'last 2 chrome versions'], //browserlist 사이트 참고
},
debug : true,
}],
'@babel/preset-react',
],
plugins : [
'@babel/plugin-proposal-class-properties',
'react-refresh/babel',
],
}
}]
},
// 웹팩기능 외의 추가작업
plugins : [
new webpackRefresh() // 핫로더 사용
],
//출력
output : {
path : path.join(__dirname, 'dist'),
filename : 'app.js',
publicPath : '/dist',
},
devServer: { //핫로더 서버
devMiddleware : { publicPath : '/dist'},
static : { directory : path.resolve(__dirname)},
hot: true,
},
}