Giter VIP home page Giter VIP logo

Comments (1)

BKJang avatar BKJang commented on May 26, 2024

pacakage.json 세팅

npm init -y

eslint 세팅 및 실행

npx eslint --init
eslint **/*.js --fix
npx와 npm의 차이?
  • npm : 서버에서 받은 라이브러리를 하드디스크에 저장한다.
  • npx : 서버에서 받은 라이브러리를 레지스트리에 올리고 cpu가 바로 사용한다.

Babel 세팅(Babel 7 기준)

npm i -D @babel/core @babel/preset-env @babel/perset-react 
  • Webpack과 같은 모듈 번들러에서 Babel 설정을 읽기 위한 라이브러리
npm i -D babel-loader 
  • .babelrc
{
    "presets" : ["@babel/preset-env", "@babel/preset-react"],
    "plugins": [ ... ]
}

Webpack 세팅

  • Webpack 설치
npm install -D webpack webpack-cli
  • webpack.config.js
module.exports = {
    module: {
        rules: [
            {
                test: /\.(js | jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            },
        ],
        resolve : {
                extensions : ['*', '.jsx', '.js']
        },
    }
}

entry 파일 설정의 default는 src/index.js
output 설정의 default는 main/dist.js
entry는 무조건 .js파일을 설정

webpack --mode development
webpack --mode production

development : minify가 적용되지 않은 상태
production : minify가 적용된 상태

React 설치

npm install react react-dom
  1. index.js 수정
  2. App.js 작성
  3. index.html 작성
  4. html-webpack-pluginhtml-loader 설치
npm install -D html-webpack-plugin html-loader
  • webpack.config.js 수정
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    module: {
        rules: [
           ... ,
            {
                test: /\.html$/,
                exclude: /node_modules/,
                use: {
                    loader: "html-loader",
                    options: {minimize: true}
                }
            }
        ]
    },
    plugins : [
        new HtmlWebpackPlugin({
            template: "./public/index.html",
            filename: "./index.html"
        })
    ]
}

webpack-dev-server 설치

npm install --save-dev webpack-dev-server 
  • webpack-dev-server 관련 설정 : webpack.config.js
module.exports = {
    module: {
        rules: [ ... ]
    },
    plugins : [ ... ],
    devServer: {
        open : true,
        port: 3000
    }
}
  • webpack-dev-server 실행
webpack-dev-server

Bonus

  • husky 설치 : Git의 hooks를 쓰기 편하게 만들어준다.
  • lint-staged 설치
npm install --save-dev husky lint-staged
  • package.json
"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.js": [
      "npm run lint:fix",
      "git add"
    ]
  },

Sample

from dev-tips.

Related Issues (20)

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.