inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

프론트엔드 개발환경의 이해와 실습 (webpack, babel, eslint..)

API 서버 연동

webpack 5에서 before 함수 안되시는분들 onBeforeSetupMiddleware로 변경됨

612

라푼젤

작성한 질문수 31

3

before함수 에러 나시는분들 업그레이드 되면서 onBeforeSetupMiddleware로 변경되었습니다. 참고하세요

devserve eslint before 웹팩 nodejs babel

답변 1

2

이준호

onBeforeSetupMiddleware 이 deprecated될꺼라서 webpack 공식 문서에 있는 setupMiddlewares를 사용해보시는게 좋을 거 같습니다. 

before는 실행되는 여러개 함수 중에서 먼저 실행되는 거라 실행할함수의 배열 제일 첫단에 넣는 건데 공식문서에는 unshift로 넣고 있습니다.

마지막에 return middlewares하셔야 됩니다 

devServer: {
    setupMiddlewares: (middlewares, devServer) => {
      if (!devServer) {
        throw new Error('webpack-dev-server is not defined');
      }

      devServer.app.get('/setup-middleware/some/path', (_, response) => {
        response.send('setup-middlewares option GET');
      });

      // Use the `unshift` method if you want to run a middleware before all other middlewares
      // or when you are migrating from the `onBeforeSetupMiddleware` option
      middlewares.unshift({
        name: 'fist-in-array',
        // `path` is optional
        path: '/foo/path',
        middleware: (req, res) => {
          res.send('Foo!');
        },
      });

      // Use the `push` method if you want to run a middleware after all other middlewares
      // or when you are migrating from the `onAfterSetupMiddleware` option
      middlewares.push({
        name: 'hello-world-test-one',
        // `path` is optional
        path: '/foo/bar',
        middleware: (req, res) => {
          res.send('Foo Bar!');
        },
      });

      middlewares.push((req, res) => {
        res.send('Hello World!');
      });

      return middlewares;
    },
  },

지금 시점에서 해당 강의를 듣는 것에 대하여

1

114

3

2025년 기준 번들러 트렌드와 선택 기준이 궁금합니다 (Webpack, Vite, tsup 등)

1

231

1

에러 해결 공유드립니다

1

225

2

webpack 4 버전과 호환되는 플러그인 버전 공유드립니다

1

234

2

eslint

0

384

3

도와주세요!

0

167

2

[수강 중 트러블슈팅 공유] webpack, webpack-cli 버전

1

149

1

질문 an error occurred while loading the image

1

473

1

webpack에서 babel-loader 사용할때 질문

1

153

1

자주 사용하는 플러그인 에서 질문이 있습니다.

1

169

1

eslint no-extra-semi 관련 질문

1

145

1

webpack5 에서 open index.html하는법 + 질문

1

170

1

TypeError: ((process.env.NODE_ENV === "production") && [MiniCssExtractPlugin]) is not iterable

2

305

1

혹시 웹팩 5 내용으로 강의 업데이트는 안되는건가요?

1

373

1

에러없이 png안뜨시는 분들

1

278

1

Error: Cannot find module 'node:crypto'

1

466

1

DefinePlugin 관련; env와 관련하여, (21.06.22 16:15, aloha_jh) 답변포함

1

412

1

깃허브 확인 문의

0

577

1

폴더를 prettier로 돌렸을 때 나오는 에러 구문에 대한 질문

0

408

1

해쉬값과 캐쉬 갱신

1

462

1

Hash 에러 발생

1

2670

2

webpack.config.js에서의 CommonJS방식에 대한 질문

0

832

3

웹팩 버전

0

526

1

웹팩-cli 버전을 명시하지 않으면 왜 에러가 날까요?

0

487

1