learning-react icon indicating copy to clipboard operation
learning-react copied to clipboard

20.3 서버사이드 렌더링 구현에서 수정 사항이 있습니다

Open kymkim96 opened this issue 6 years ago • 3 comments

웹팩 환경 설정 중에 paths.js를 수정하게 됩니다. 근데 CRA로 생성한 프로젝트에서 config/paths.js에 있는 publicUrl과 servedPath가 변경이 되어서 책에 있는 내용과 상이한 것을 알게 되었습니다. 코드와 설명의 수정이 필요해 보이는데 혹시 이것에 대해서 이미 알고 계신가요?

kymkim96 avatar Mar 04 '20 09:03 kymkim96

그렇네요. webpack.config.js에서 참고하시면 될것 같습니다. 기존코드에서 각각 밑 코드로 수정하시면 될것 같습니다. const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));

 publicPath: paths.publicUrlOrPath

itssosunny avatar Mar 08 '20 22:03 itssosunny

하하하.. 뭐가 또 많이 바뀌었군요~ @Neo0204 님께서 말씀하신대로 수정하시면 됩니다..!

config/webpack.config.server.js

- const publicUrl = paths.servedPath.slice(0, -1);
- const env = getClientEnvironment(publicUrl);
+ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));

(...)
module.exports = {
  mode: 'production',
  entry: paths.ssrIndexJs,
  target: 'node',
  output: {
    path: paths.ssrBuild,
    filename: 'server.js',
    chunkFilename: 'js/[name].chunk.js',
-    publicPath: paths.servedPath
+    publicPath: paths.publicUrlOrPath
  },

감사합니다.

주말에 프로젝트 업데이트도 하고 corrections.md 도 고치겠습니다~

velopert avatar Mar 09 '20 15:03 velopert

https://github.com/velopert/learning-react/blob/master/corrections.md#2032-pg546--552-%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8

에 수정되어있습니다~

velopert avatar Jun 22 '20 16:06 velopert