|
| 1 | +# 오탈자 및 개선사항 |
| 2 | + |
| 3 | +여기에 있는 내용은 개정판 3쇄 이상 기준입니다. |
| 4 | +개정판 1~3쇄에 기준한 업데이트 사항은 다음 링크에서 확인하세요: |
| 5 | + |
| 6 | +- [개정판-1쇄.md](https://github.com/velopert/learning-react/blob/master/_old_corrections/%EA%B0%9C%EC%A0%95%ED%8C%90-1%EC%87%84.md) |
| 7 | +- [개정판-2쇄.md](https://github.com/velopert/learning-react/blob/master/_old_corrections/%EA%B0%9C%EC%A0%95%ED%8C%90-2%EC%87%84.md) |
| 8 | +- [개정판-3쇄.md](https://github.com/velopert/learning-react/blob/master/_old_corrections/%EA%B0%9C%EC%A0%95%ED%8C%90-3%EC%87%84.md) |
| 9 | + |
| 10 | +### 모든 프로젝트의 index.js |
| 11 | + |
| 12 | +기존에는 src/index.js 파일에 serviceWorker.js 파일을 불러와서 `serviceWorker.unregister()` 가 있었는데 CRA가 업데이트 되면서 해당 부분이 사라졌습니다. 따라서 해당 부분은 모두 무시하시면 됩니다. 또한, `import * as serviceWorker from './serviceWorker';` 부분도 무시하시면 됩니다. |
| 13 | + |
| 14 | +영향이 가는 페이지 |
| 15 | + |
| 16 | +- pg. 61 |
| 17 | +- pg. 327 |
| 18 | +- pg. 382 |
| 19 | +- pg. 443-444 |
| 20 | +- pg. 445 |
| 21 | +- pg. 474 |
| 22 | +- pg. 479 |
| 23 | +- pg. 480-481 |
| 24 | +- pg. 484 |
| 25 | +- pg. 507 |
| 26 | +- pg. 509 |
| 27 | +- pg. 544 |
| 28 | +- pg. 566 |
| 29 | +- pg. 580 |
| 30 | +- pg. 723 |
| 31 | +- pg. 730-731 |
| 32 | +- pg. 768 |
| 33 | +- pg. 799-800 |
| 34 | +- pg. 893 |
| 35 | + |
| 36 | +## 8.2.3 오탈자 pg.197 |
| 37 | + |
| 38 | +useEffect 부분에 deps 배열이 빠져있습니다. |
| 39 | + |
| 40 | +```javascript |
| 41 | +useEffect(() => { |
| 42 | + console.log('effect'); |
| 43 | + console.log(name); |
| 44 | + return () => { |
| 45 | + console.log('cleanup'); |
| 46 | + console.log(name); |
| 47 | + }; |
| 48 | +}, [name]); |
| 49 | +``` |
| 50 | + |
| 51 | +## 8.2.3 오탈자 pg.199 |
| 52 | + |
| 53 | +배열을 비워야 합니다. |
| 54 | + |
| 55 | +```javascript |
| 56 | +useEffect(() => { |
| 57 | + console.log('effect'); |
| 58 | + console.log(name); |
| 59 | + return () => { |
| 60 | + console.log('cleanup'); |
| 61 | + console.log(name); |
| 62 | + }; |
| 63 | +}, []); |
| 64 | +``` |
| 65 | + |
| 66 | +### 20.3.2 업데이트 (pg.546 - pg.547) |
| 67 | + |
| 68 | +CRA 업데이트됨에 따라 paths 파일이 변경되었습니다. |
| 69 | + |
| 70 | +```diff |
| 71 | +module.exports = { |
| 72 | + dotenv: resolveApp('.env'), |
| 73 | + appPath: resolveApp('.'), |
| 74 | + appBuild: resolveApp('build'), |
| 75 | + appPublic: resolveApp('public'), |
| 76 | + appHtml: resolveApp('public/index.html'), |
| 77 | + appIndexJs: resolveModule(resolveApp, 'src/index'), |
| 78 | + appPackageJson: resolveApp('package.json'), |
| 79 | + appSrc: resolveApp('src'), |
| 80 | + appTsConfig: resolveApp('tsconfig.json'), |
| 81 | + appJsConfig: resolveApp('jsconfig.json'), |
| 82 | + yarnLockFile: resolveApp('yarn.lock'), |
| 83 | + testsSetup: resolveModule(resolveApp, 'src/setupTests'), |
| 84 | + proxySetup: resolveApp('src/setupProxy.js'), |
| 85 | + appNodeModules: resolveApp('node_modules'), |
| 86 | ++ swSrc: resolveModule(resolveApp, 'src/service-worker'), |
| 87 | + publicUrlOrPath, |
| 88 | + ssrIndexJs: resolveApp('src/index.server.js'), |
| 89 | + ssrBuild: resolveApp('dist'), |
| 90 | +}; |
| 91 | +``` |
| 92 | + |
| 93 | +### 20.30.2 업데이트 (pg.548 - 550) |
| 94 | + |
| 95 | +CRA 업데이트됨에 따라 webpack.config.server.js 파일이 변경되었습니다. |
| 96 | + |
| 97 | +```javascript |
| 98 | +const paths = require('./paths'); |
| 99 | +const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent'); |
| 100 | + |
| 101 | +const cssRegex = /\.css$/; |
| 102 | +const cssModuleRegex = /\.module\.css$/; |
| 103 | +const sassRegex = /\.(scss|sass)$/; |
| 104 | +const sassModuleRegex = /\.module\.(scss|sass)$/; |
| 105 | + |
| 106 | +const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1)); |
| 107 | + |
| 108 | +module.exports = { |
| 109 | + mode: 'production', |
| 110 | + entry: paths.ssrIndexJs, |
| 111 | + target: 'node', |
| 112 | + output: { |
| 113 | + path: paths.ssrBuild, |
| 114 | + filename: 'server.js', |
| 115 | + chunkFilename: 'js/[name].chunk.js', |
| 116 | + publicPath: paths.publicUrlOrPath, |
| 117 | + }, |
| 118 | + module: { |
| 119 | + rules: [ |
| 120 | + { |
| 121 | + oneOf: [ |
| 122 | + // 자바스크립트를 위한 처리 |
| 123 | + // 기존 webpack.config.js 를 참고하여 작성 |
| 124 | + { |
| 125 | + test: /\.(js|mjs|jsx|ts|tsx)$/, |
| 126 | + include: paths.appSrc, |
| 127 | + loader: require.resolve('babel-loader'), |
| 128 | + options: { |
| 129 | + customize: require.resolve( |
| 130 | + 'babel-preset-react-app/webpack-overrides' |
| 131 | + ), |
| 132 | + presets: [ |
| 133 | + [ |
| 134 | + require.resolve('babel-preset-react-app'), |
| 135 | + { |
| 136 | + runtime: 'automatic', |
| 137 | + }, |
| 138 | + ], |
| 139 | + ], |
| 140 | + plugins: [ |
| 141 | + [ |
| 142 | + require.resolve('babel-plugin-named-asset-import'), |
| 143 | + { |
| 144 | + loaderMap: { |
| 145 | + svg: { |
| 146 | + ReactComponent: |
| 147 | + '@svgr/webpack?-svgo,+titleProp,+ref![path]', |
| 148 | + }, |
| 149 | + }, |
| 150 | + }, |
| 151 | + ], |
| 152 | + ], |
| 153 | + cacheDirectory: true, |
| 154 | + cacheCompression: false, |
| 155 | + compact: false, |
| 156 | + }, |
| 157 | + }, |
| 158 | + // CSS 를 위한 처리 |
| 159 | + { |
| 160 | + test: cssRegex, |
| 161 | + exclude: cssModuleRegex, |
| 162 | + // exportOnlyLocals: true 옵션을 설정해야 실제 css 파일을 생성하지 않습니다. |
| 163 | + loader: require.resolve('css-loader'), |
| 164 | + options: { |
| 165 | + importLoaders: 1, |
| 166 | + modules: { |
| 167 | + exportOnlyLocals: true, |
| 168 | + }, |
| 169 | + }, |
| 170 | + }, |
| 171 | + // CSS Module 을 위한 처리 |
| 172 | + { |
| 173 | + test: cssModuleRegex, |
| 174 | + loader: require.resolve('css-loader'), |
| 175 | + options: { |
| 176 | + importLoaders: 1, |
| 177 | + modules: { |
| 178 | + exportOnlyLocals: true, |
| 179 | + getLocalIdent: getCSSModuleLocalIdent, |
| 180 | + }, |
| 181 | + }, |
| 182 | + }, |
| 183 | + // Sass 를 위한 처리 |
| 184 | + { |
| 185 | + test: sassRegex, |
| 186 | + exclude: sassModuleRegex, |
| 187 | + use: [ |
| 188 | + { |
| 189 | + loader: require.resolve('css-loader'), |
| 190 | + options: { |
| 191 | + importLoaders: 3, |
| 192 | + modules: { |
| 193 | + exportOnlyLocals: true, |
| 194 | + }, |
| 195 | + }, |
| 196 | + }, |
| 197 | + require.resolve('sass-loader'), |
| 198 | + ], |
| 199 | + }, |
| 200 | + // Sass + CSS Module 을 위한 처리 |
| 201 | + { |
| 202 | + test: sassRegex, |
| 203 | + exclude: sassModuleRegex, |
| 204 | + use: [ |
| 205 | + { |
| 206 | + loader: require.resolve('css-loader'), |
| 207 | + options: { |
| 208 | + importLoaders: 3, |
| 209 | + modules: { |
| 210 | + exportOnlyLocals: true, |
| 211 | + getLocalIdent: getCSSModuleLocalIdent, |
| 212 | + }, |
| 213 | + }, |
| 214 | + }, |
| 215 | + require.resolve('sass-loader'), |
| 216 | + ], |
| 217 | + }, |
| 218 | + // url-loader 를 위한 설정 |
| 219 | + { |
| 220 | + test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], |
| 221 | + loader: require.resolve('url-loader'), |
| 222 | + options: { |
| 223 | + emitFile: false, // 파일을 따로 저장하지 않는 옵션 |
| 224 | + limit: 10000, // 원래는 9.76KB가 넘어가면 파일로 저장하는데 |
| 225 | + // emitFile 값이 false 일땐 경로만 준비하고 파일은 저장하지 않습니다. |
| 226 | + name: 'static/media/[name].[hash:8].[ext]', |
| 227 | + }, |
| 228 | + }, |
| 229 | + // 위에서 설정된 확장자를 제외한 파일들은 |
| 230 | + // file-loader 를 사용합니다. |
| 231 | + { |
| 232 | + loader: require.resolve('file-loader'), |
| 233 | + exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/], |
| 234 | + options: { |
| 235 | + emitFile: false, // 파일을 따로 저장하지 않는 옵션 |
| 236 | + name: 'static/media/[name].[hash:8].[ext]', |
| 237 | + }, |
| 238 | + }, |
| 239 | + ], |
| 240 | + }, |
| 241 | + ], |
| 242 | + }, |
| 243 | +}; |
| 244 | +``` |
| 245 | + |
| 246 | +### 20.30.2 업데이트 (pg.552) |
| 247 | + |
| 248 | +CRA 업데이트됨에 따라 nodeExternals에 allowlist 설정이 필요해졌습니다. |
| 249 | + |
| 250 | +```javascript |
| 251 | +const nodeExternals = require('webpack-node-externals'); |
| 252 | + |
| 253 | +(...) |
| 254 | +module.exports = { |
| 255 | + (...) |
| 256 | + resolve: { |
| 257 | + modules: ['node_modules'], |
| 258 | + }, |
| 259 | + externals: [ |
| 260 | + nodeExternals({ |
| 261 | + allowlist: [/@babel/], |
| 262 | + }), |
| 263 | + ], |
| 264 | +} |
| 265 | +``` |
| 266 | + |
| 267 | +## 22.9.2 업데이트 pg.669 |
| 268 | + |
| 269 | +@hapi/joi 에서 joi 로 변경되었습니다. |
| 270 | + |
| 271 | +``` |
| 272 | +$ yarn add @hapi/joi |
| 273 | +``` |
| 274 | + |
| 275 | +```javascript |
| 276 | +import Joi from 'joi'; |
| 277 | +``` |
| 278 | + |
| 279 | +영향 가는 페이지: 691, 861, 862, |
0 commit comments