Coder Social home page Coder Social logo

react-project's Introduction

React-Project

react-not-cra에서 공부한 토대로 react 프로젝트를 만들어보기.

실행

npm install 
npm run build
npm rnu dev

webpack, babel 설치 및 설정

npm i -D babel @babel/preset-env @babel/preset-react
npm i -D webpack webpack-cli webpack-dev-server
npm i -D babel-loader html-loader style-loader css-loader
//.babelrc
{
    "presets":[
        "@babel/preset-env",
        "@babel/preset-react"
    ]
}
//webpack.config.js 기본 설정
module.exports = {
  mode : "development",
  entry: "./src/app.js",
  output: {
    filename: "bundle_[hash].js",
    path: path.resolve("./dist"),
    clean: true,
  },
  devServer: {
    host: "localhost",
    port: 8080,
    open: true,
    watchFiles: "index.html",
    historyApiFallback: true,
  },
  module{
      rules:[
           {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: ["babel-loader"],
            },
            {
                test: /\.html$/,
                exclude: /node_modules/,
                use: ["html-loader"],
            },
            {
                test: /\.css$/,
                exclude: /node_modules/,
                use: ["style-loader", "css-loader"],
            },
      ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./src/template.html",
      inject: "body",
      title: "react-no-cra",
    }),
    
  ],
  optimization:{
      minimizer:[
        new cssMinimizerWebpackPlugin()
      ]
  }
}

ESLint, Prettier, Husky 설정

npm i -D eslint prettier eslint-config-prettier
npm i -D husky lint-staged

ESLint 설정 -> npx eslint --init 에서 리액트로
Prettier 설정 -> 공식문서의 디폴트 설정

//husky설정
npx husky install
npx husky add .husky/pre-commit "npx lint-staged"

//package.json
"lint-staged": {
    "src/*.js": "eslint --fix",
    "src/*.jsx": "eslint --fix"
},

Trouble-Shooting

  • webpack-dev-server의 라우팅 문제
    webpack-dev-server config인 devServer에 historyApiFallback:true를 추가 해야함. 이유는 가상의 서버를 띄운 것이기에 브라우저 입장에서는 서버가 없는 거임. 그래서 history API를 추가해주기!
  • style.css module import -> undefined
    이름 규칙이 있었었음. {name}.module.css로 이름을 지어야함..
  • regeneratorRuntime is not defined 발생
    원인 : react애서 async/await을 사용하는 경우 나타나는 에러.
    이유 : 어플리케이션이 컴파일 될 때 regeneratorRuntime이 문법을 번역하는데 이게 없어서 그럼
    해결 방법 : babel의 @babel/plugin-transform-runtime 플러그인을 추가한다.
npm install --save-dev @babel/plugin-transform-runtime
npm install --save @babel/runtime

//.babelrc
"plugins": ["@babel/plugin-transform-runtime"]

react-project's People

Contributors

deeeeno avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.