inflearn logo
강의

Course

Instructor

Applying TypeScript to React while learning while making web games

useCallback typing

babel-loader질문입니다! 왜쓰는지 궁금합니다!

685

rud167637

1 asked

0

react-typescript강좌 끝말잇기 부분에서 미래에서 온 제로초님께서

webpack.config.ts파일에 추가하라고 하신 babel-loader에 관해서 질문이 있습니다.

module설정하는 부분에 babel-loader를 추가해주었는데 버전이 업데이트 되면서 왜 이 로더를 추가해야될까요??

 

그리고 에러를 해결하는 과정에서 질문이있습니다. module.rules 부분에 순서는 상관없다고 생각해서 ts-loader설정을 먼저 적고 babel-loader를 적어주었습니다. 그러나 아래와 같이 오류가 떳습니다

그러나 설정 순서를 바꿔주었더니 해결이 되었는데 어떤 처리과정이 있길래 이 순서를 바꿔주어서 해결을 할 수 있게됬는지 의문입니다.

아래는 해결되서 적어놓은 webpack.config.ts파일입니다!

import path from 'node:path';
import ReactRefreshPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import { Configuration as WebpackConfiguration } from "webpack";
import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";

interface Configuration extends WebpackConfiguration {
  devServer?: WebpackDevServerConfiguration;
}

const config: Configuration = {
  name: 'word-relay-dev',
  mode: 'development', //after production
  devtool: 'eval',
  resolve: {
    extensions: ['.jsx', '.js', '.tsx', '.ts'],
  },
  entry: {
    app: './client'
  },
  module: {
    rules: [
      {
        loader: 'babel-loader',
        options: { plugins: ['react-refresh/babel'] },
      },
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        exclude: path.join(__dirname, 'node_modules'),
      },]
  },
  plugins: [
    new ReactRefreshPlugin(),
    new ForkTsCheckerWebpackPlugin()
  ],
  output: {
    filename: '[name].js',
    path: path.join(__dirname, 'dist'),
    publicPath: '/dist/',
  }, devServer: {
    devMiddleware: { publicPath: '/dist' },
    static: { directory: path.resolve(__dirname) },
    hot: true
  }


}

export default config;

react typescript

Answer 1

0

zerocho

사실 이 강좌도 연식이 좀 된지라 이제는 ts-loader만 해도 됩니다. 여기서는 react-refresh/babel을 쓰려고 같이 썼습니다.

모듈 순서는 매우 중요합니다. 그 역순서대로 처리되니까요. ts-loader가 ts를 js로 바꾼 뒤에 babel-loader가 핫 리로딩을 붙입니다.

express response 타입

0

210

1

createRoot

0

285

1

undefined 처리

0

493

1

compilerOptions lib 관련

0

329

1

event type 찾기

0

324

1

정확한 type vs 가독성

0

292

1

useRef에 대해 질문드립니다.

0

305

1

tsx파일에서 에러 표시

0

864

1

Props type 질문드립니다.

0

227

1

webpack.config.ts/ Could not find a declaration file for module '@pmmmwh/react-refresh-webpack-plugin'.

0

590

1

18버전에서의 ReactDOM.render

1

658

1

깃허브에 react-router@6 업데이트 해주신 코드 질문드립니다.

0

294

1

2강 끝말잇기 npx webpack 오류가 질의사항

0

408

1

Property 'render' does not exist on type 'IntrinsicAttributes & (PathRouteProps | LayoutRouteProps | IndexRouteProps)'.

0

716

1

webpack.config.ts import 할 때 에러좀 봐주세요!!

0

307

1

React.FC에 대해 궁금합니다.

0

701

1

가위바위보 interval 타입과 이벤트타입에 관한질문

0

343

1

npm run dev 실행은 성공적으로 되는데

0

677

2

redux 유료강좌를 듣고 와야 되는지 여쭈어보려고 합니다.

0

320

1

git 내용과 강의 내용이 달라서 여쭈어봅니다.

0

223

1

Ball.tsx 타이핑

0

324

2

react-router 버젼 업그레이드 변경사항 문의

0

286

2

리액트 타입스크립트 공식문서

0

338

1

button 클릭 할 떄 마다 더보기/닫기 에러

0

856

1