728x90

create-react-app을 이용한 React 초기 개발 환경 설정

참고URL

https://xiubindev.tistory.com/92 

https://velog.io/@cjy9306/create-react-app%EC%97%90%EC%84%9C-react%EA%B0%80-%EC%8B%A4%ED%96%89%EB%90%98%EB%8A%94-%EA%B8%B0%EB%B3%B8-%EC%9B%90%EB%A6%AC-yjk56rqzlk

 

Yarn - 개선된 버전의 npm

리눅스, 혹은 macOS 에서 nvm 을 통하여 Node.js 를 설치했다면 yarn global 설치가 제대로 작동하기 위해선 다음 커맨드를  profile에 입력해줘야 합니다.

-- macOS
$ echo 'export PATH="$(yarn global bin):$PATH"' >> ~/.bash_profile

-- Linux
$ echo 'export PATH="$(yarn global bin):$PATH"' >> ~/.bashrc

 

1. create-react-app 설치

$ npm install -g create-react-app

또는 

$ yarn global add create-react-app

 

2. react app 생성

$ create-react-app first-react-app

 


 

$ npx create-react-app firstReactApp

카멜방식의 프로젝트는 생성할 수 없습니다.

단어사이에 대문자를 넣지 말고 "-" 으로 표기하여 폴더를 생성하여야 합니다.

$ npx create-react-app firstReactApp

npx: 98개의 패키지를 3.66초만에 설치했습니다.
Cannot create a project named "firstReactApp" because of npm naming restrictions:

  * name can no longer contain capital letters

Please choose a different project name.


$ cd firstReactApp
-bash: cd: firstReactApp: No such file or directory

 

$ npx create-react-app first-react-app

리엑트 프로젝트 생성 

$ npx create-react-app first-react-app
npx: 98개의 패키지를 3.102초만에 설치했습니다.

Creating a new React app in /Users/jaehonghan/dev/workspace_nodejs/first-react-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

yarn add v1.22.4
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] 🔨  Building fresh packages...
[1/4] ⡀ fsevents
[-/4] ⡀ waiting...
[-/4] ⡀ waiting...
warning Error running install script for optional dependency: "/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: /Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@14.4.0 | darwin | x64
gyp info find Python using Python version 2.7.16 found at \"/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python\"
gyp info spawn /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
gyp info spawn args [
gyp info spawn args   '/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/jaehonghan/Library/Caches/node-gyp/14.4.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/jaehonghan/Library/Caches/node-gyp/14.4.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/jaehonghan/Library/Caches/node-gyp/14.4.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 19.5.0
gyp ERR! command \"/usr/local/Cellar/node/14.4.0/bin/node\" \"/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents
gyp ERR! node -v v14.4.0
success Saved lockfile.
success Saved 14 new dependencies.
info Direct dependencies
├─ cra-template@1.0.3
├─ react-dom@16.13.1
├─ react-scripts@3.4.1
└─ react@16.13.1
info All dependencies
├─ @babel/plugin-syntax-typescript@7.10.4
├─ @babel/plugin-transform-flow-strip-types@7.9.0
├─ @babel/plugin-transform-runtime@7.9.0
├─ @babel/plugin-transform-typescript@7.10.4
├─ @babel/preset-typescript@7.9.0
├─ babel-preset-react-app@9.1.2
├─ cra-template@1.0.3
├─ eslint-config-react-app@5.2.1
├─ react-dev-utils@10.2.1
├─ react-dom@16.13.1
├─ react-error-overlay@6.0.7
├─ react-scripts@3.4.1
├─ react@16.13.1
└─ scheduler@0.19.1
✨  Done in 11.28s.

Initialized a git repository.

Installing template dependencies using yarnpkg...
yarn add v1.22.4
[1/4] 🔍  Resolving packages...
warning @testing-library/react > @types/testing-library__react > @types/testing-library__dom@7.5.0: This is a stub types definition. testing-library__dom provides its own type definitions, so you do not need this installed.
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
[4/4] 🔨  Building fresh packages...
warning Error running install script for optional dependency: "/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: /Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@14.4.0 | darwin | x64
gyp info find Python using Python version 2.7.16 found at \"/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python\"
gyp info spawn /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
gyp info spawn args [
gyp info spawn args   '/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/jaehonghan/Library/Caches/node-gyp/14.4.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/jaehonghan/Library/Caches/node-gyp/14.4.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/jaehonghan/Library/Caches/node-gyp/14.4.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 19.5.0
gyp ERR! command \"/usr/local/Cellar/node/14.4.0/bin/node\" \"/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents
gyp ERR! node -v v14.4.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok"
info This module is OPTIONAL, you can safely ignore this error
success Saved lockfile.
success Saved 21 new dependencies.
info Direct dependencies
├─ @testing-library/jest-dom@4.2.4
├─ @testing-library/react@9.5.0
├─ @testing-library/user-event@7.2.1
├─ react-dom@16.13.1
└─ react@16.13.1
info All dependencies
├─ @babel/runtime-corejs3@7.10.4
├─ @sheerun/mutationobserver-shim@0.3.3
├─ @testing-library/dom@6.16.0
├─ @testing-library/jest-dom@4.2.4
├─ @testing-library/react@9.5.0
├─ @testing-library/user-event@7.2.1
├─ @types/prop-types@15.7.3
├─ @types/react-dom@16.9.8
├─ @types/react@16.9.41
├─ @types/testing-library__dom@7.5.0
├─ @types/testing-library__react@9.1.3
├─ aria-query@4.2.2
├─ css.escape@1.5.1
├─ csstype@2.6.10
├─ dom-accessibility-api@0.3.0
├─ min-indent@1.0.1
├─ react-dom@16.13.1
├─ react@16.13.1
├─ redent@3.0.0
├─ strip-indent@3.0.0
└─ wait-for-expect@3.0.2
✨  Done in 6.09s.
Removing template package using yarnpkg...

yarn remove v1.22.4
[1/2] 🗑  Removing module cra-template...
[2/2] 🔨  Regenerating lockfile and installing missing dependencies...
warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[-/4] ⢀ waiting...
[2/4] ⢀ fsevents
[-/4] ⢀ waiting...
warning Error running install script for optional dependency: "/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: /Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@14.4.0 | darwin | x64
gyp info find Python using Python version 2.7.16 found at \"/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python\"
gyp info spawn /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
gyp info spawn args [
gyp info spawn args   '/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/jaehonghan/Library/Caches/node-gyp/14.4.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/jaehonghan/Library/Caches/node-gyp/14.4.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/jaehonghan/Library/Caches/node-gyp/14.4.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 19.5.0
gyp ERR! command \"/usr/local/Cellar/node/14.4.0/bin/node\" \"/usr/local/Cellar/node/14.4.0/libexec/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /Users/jaehonghan/dev/workspace_nodejs/first-react-app/node_modules/fsevents
gyp ERR! node -v v14.4.0
success Uninstalled packages.
✨  Done in 5.94s.

Created git commit.

Success! Created first-react-app at /Users/jaehonghan/dev/workspace_nodejs/first-react-app
Inside that directory, you can run several commands:

  yarn start
    Starts the development server.

  yarn build
    Bundles the app into static files for production.

  yarn test
    Starts the test runner.

  yarn eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd first-react-app
  yarn start

Happy hacking!

 

npm start 또는 yarn start

브라우저 창에 http://localhost:3000/로 접속하시면 에 react 초기 페이지 나타납니다.

 

$ yarn start

$ yarn start

........


Compiled successfully!

You can now view first-react-app in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://192.168.0.54:3000

Note that the development build is not optimized.
To create a production build, use yarn build.

 

http://localhost:3000/

 

728x90

참고URL

https://codinghub.tistory.com/39

 


Babel 
ECMAScript6를 지원하지 않는 환경에서 ECMAScript6 Syntax를 사용할 수 있게 해줍니다.

Webpack
모듈 번들러입니다.
Browserify 처럼 브라우저 위에서 import(require)을 할 수 있게 해주고 자바스크립트 파일들을 하나로 묶어 줍니다.

webpack-dev-server
webpack에서 지원하는 간단한 개발서버로써 별도의 서버를 구축하지 않아도 웹서버를 열 수 있으며 hot-loader 를 통하여 코드가 수정될때마다 자동으로 리로드되게 할 수 있습니다.


프로젝트를 위한 폴더 생성 및 npm 초기화 - 폴더명 myFristApp

$ mkdir myFirstApp
$ cd  myFirstApp
$ npm init

$ npm init

This utility will walk you through creating a package.json file.

It only covers the most common items, and tries to guess sensible defaults.



See `npm help json` for definitive documentation on these fields

and exactly what they do.



Use `npm install <pkg>` afterwards to install a package and

save it as a dependency in the package.json file.



Press ^C at any time to quit.

package name: (reactjs) 

version: (1.0.0) 

description: 

entry point: (index.js) 

test command: 

git repository: 

keywords: 

author: 

license: (ISC) 

About to write to /Users/jaehonghan/dev/workspace_nodejs/reactjs/package.json:



{

  "name": "reactjs",

  "version": "1.0.0",

  "description": "",

  "main": "index.js",

  "scripts": {

    "test": "echo \"Error: no test specified\" && exit 1"

  },

  "author": "",

  "license": "ISC"

}



Is this OK? (yes) 

 

package.json에 webpack-dev-server 스크립트 추가

package.json에 "dev-server":"webpack-dev-server" 추가해야 합니다.

추후 개발 서버를 실행하기 위해서 필요합니다.

 

$ vi package.json

{
  "name": "reactjs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev-server":"webpack-dev-server" 
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.1.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-react-hmre": "^1.1.1",
    "babel-preset-stage-0": "^6.24.1",
    "css-loader": "^3.6.0",
    "file-loader": "^6.0.0",
    "node-sass": "^4.14.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-hot-loader": "^4.12.21",
    "sass-loader": "^8.0.2",
    "style-loader": "^1.2.1",
    "url-loader": "^4.1.0",
    "webpack": "^4.43.0",
    "webpack-dev-middleware": "^3.7.2",
    "webpack-dev-server": "^3.11.0",
    "webpack-hot-middleware": "^2.25.0"
  },
  "dependencies": {
    "bootstrap": "^4.5.0",
    "react-bootstrap": "^1.0.1"
  }
}

 

리엑트 설치

$ npm install --save-dev react react-dom

$ npm install --save-dev react react-dom


npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ react-dom@16.13.1

+ react@16.13.1

added 8 packages from 3 contributors and audited 8 packages in 0.695s

found 0 vulnerabilities

 

부트스트랩 설치

$ npm install --save bootstrap react-bootstrap

$ npm install --save bootstrap react-bootstrap

npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ react-bootstrap@1.0.1

+ bootstrap@4.5.0

added 22 packages from 43 contributors and audited 30 packages in 2.929s



2 packages are looking for funding

  run `npm fund` for details



found 0 vulnerabilities

 

css /  sass 설치

$ npm install --save-dev sass-loader css-loader style-loader node-sass

$ npm install --save-dev sass-loader css-loader style-loader node-sass

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142



> node-sass@4.14.1 install /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass

> node scripts/install.js



Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/darwin-x64-83_binding.node

Download complete░░⸩ ⠋ :

Binary saved to /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass/vendor/darwin-x64-83/binding.node

Caching binary to /Users/jaehonghan/.npm/node-sass/4.14.1/darwin-x64-83_binding.node



> node-sass@4.14.1 postinstall /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass

> node scripts/build.js



Binary found at /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass/vendor/darwin-x64-83/binding.node

Testing binary

Binary is fine

npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN sass-loader@8.0.2 requires a peer of webpack@^4.36.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN css-loader@3.6.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN style-loader@1.2.1 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ sass-loader@8.0.2

+ css-loader@3.6.0

+ node-sass@4.14.1

+ style-loader@1.2.1

added 224 packages from 177 contributors and audited 254 packages in 9.398s



11 packages are looking for funding

  run `npm fund` for details



found 0 vulnerabilities

 

 

Babel 설치

$ npm install --save-dev babel-core babel-loader babel-cli babel-preset-react babel-preset-es2015 babel-preset-stage-0 babel-polyfill babel-preset-env file-loader url-loader babel-preset-react-hmre

$ npm install --save-dev babel-core babel-loader babel-cli babel-preset-react babel-preset-es2015 babel-preset-stage-0 babel-polyfill babel-preset-env file-loader url-loader babel-preset-react-hmre



npm WARN deprecated babel-preset-es2015@6.24.1: 🙌  Thanks for using Babel: we recommend using babel-preset-env now: please read https://babeljs.io/env to update!

npm WARN deprecated chokidar@1.7.0: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.

npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated

npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated



> fsevents@1.2.13 install /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/fsevents

> node install.js



No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.



No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.



No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.



gyp: No Xcode or CLT version detected!

gyp ERR! configure error 

gyp ERR! stack Error: `gyp` failed with exit code: 1

gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)

gyp ERR! stack     at ChildProcess.emit (events.js:315:20)

gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)

gyp ERR! System Darwin 19.5.0

gyp ERR! command "/usr/local/Cellar/node/14.4.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"

gyp ERR! cwd /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/fsevents

gyp ERR! node -v v14.4.0

gyp ERR! node-gyp -v v5.1.0

gyp ERR! not ok 



> core-js@2.6.11 postinstall /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/core-js

> node -e "try{require('./postinstall')}catch(e){}"



Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!



The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 

> https://opencollective.com/core-js 

> https://www.patreon.com/zloirock 



Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)



npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN css-loader@3.6.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN sass-loader@8.0.2 requires a peer of webpack@^4.36.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN style-loader@1.2.1 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN babel-loader@8.1.0 requires a peer of @babel/core@^7.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN babel-loader@8.1.0 requires a peer of webpack@>=2 but none is installed. You must install peer dependencies yourself.

npm WARN file-loader@6.0.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN url-loader@4.1.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ babel-loader@8.1.0

+ babel-preset-env@1.7.0

+ babel-polyfill@6.26.0

+ babel-cli@6.26.0

+ babel-preset-react@6.24.1

+ babel-core@6.26.3

+ babel-preset-stage-0@6.24.1

+ file-loader@6.0.0

+ url-loader@4.1.0

+ babel-preset-react-hmre@1.1.1

+ babel-preset-es2015@6.24.1

added 314 packages from 130 contributors and audited 569 packages in 38.757s



13 packages are looking for funding

  run `npm fund` for details



found 1 low severity vulnerability

  run `npm audit fix` to fix them, or `npm audit` for details

 

.babelrc  파일 생성

$ vi .babelrc

{
   "presets":["env","react","es2015", "stage-0"],
   "env":{
      "development":{
         "presets":["react-hmre"]
      }
   }
}

 

WebPack 설치

$ npm install --save-dev react-hot-loader webpack webpack-dev-server webpack-dev-middleware webpack-hot-middleware 

$ npm install --save-dev react-hot-loader webpack webpack-dev-server webpack-dev-middleware webpack-hot-middleware 



npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"14.4.0","npm":"6.14.4"})

npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0

npm WARN babel-loader@8.1.0 requires a peer of @babel/core@^7.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ webpack-dev-middleware@3.7.2

+ webpack-hot-middleware@2.25.0

+ react-hot-loader@4.12.21

+ webpack-dev-server@3.11.0

+ webpack@4.43.0

added 463 packages from 312 contributors and audited 1033 packages in 10.309s



31 packages are looking for funding

  run `npm fund` for details



found 1 low severity vulnerability

  run `npm audit fix` to fix them, or `npm audit` for details

 

 

webpack 설정 -  webpack.config.js

프로젝트 폴더에 webpack 설정파일인 webpack.config.js 을 생성하고 아래의 내용을 입력합니다.

var webpack = require('webpack');

var path = require('path');

module.exports = {

  entry: [

    'webpack-hot-middleware/client',

    './src/index.js'

  ],

  output: {

    path: __dirname + '/public/',

    filename: 'bundle.js'

  },

  devServer: {

    hot: true,

    inline: true,

    port: 4000,

    contentBase: __dirname + '/public/',

  },

  module: {

      loaders: [

        {

          test: /\.js$/,

          loaders: ['react-hot-loader', 'babel-loader'],

          include: path.join(__dirname, 'src')

        },

        {

          test: /\.less$/,

          loader: 'style-loader!css-loader!less-loader'  // use ! to chain loaders

        },

        {

          test: /\.css$/,

          loader: 'style-loader!css-loader'

        },

        {

          test: /\.scss$/,

          loader: 'style-loader!css-loader!sass-loader'

        },

        {

          test: /\.(png|jpg)$/,

          loader: 'url-loader?limit=8192' // inline base64 URLs for <=8k images, direct URLs for the rest

        }

      ]

  },

  plugins: [ new webpack.HotModuleReplacementPlugin() ]

}

react app 만들기

1. 처음에 생성한 myFirstApp 에 public, src 폴더를 생성합니다.

webpack.config.js에서 개발 서버가 바라볼 기본 폴더는 public가 됩니다.

$ cd myFirstApp
$ mkdir public
$ mkdir src

 

2. public 폴더에 index.html 파일을 아래와 같이 생성합니다.

$ cd public/index.html

-- index.html에 간략한 내용 입력

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>React App with Babel + webpack</title>
  </head>

  <body>
    <div id="contents"></div>
    <script src="bundle.js"></script>
  </body>
</html>

 

3. src 폴더에 components 폴더를 생성합니다.

src 폴더의 하위에 components  폴더를 만들고 src/components Contents.react.js 파일을 생성하고 아래의 내용을 입력합니다.

$ cd ../src
$ mkdir components
$ vi Contents.react.js


-- Contents.react.js 파일의 내용

import React from 'react';
class Contents extends React.Component {
  render() {
    return ( <h1>React + Webpack + Babel First Apps</h1> );
  }
}

 

4. 개발 서버를 실행합니다.

브라우저에서 http://localhost:4000에 접속하시면 결과를 확인할 수 있습니다.

$ cd myFirstApp
$ npm run dev-server
728x90

참고문서

[RN] React-Native 시작하기

medium.com/@jang.wangsu/rn-react-native-%EC%8B%9C%EC%9E%91-3aab881f574f

Introduction

reactnative.dev/docs/getting-started

 

1. React-Native 시작하기 전

Homebrew 설치하기

brew.sh/index_ko

 

Homebrew

The Missing Package Manager for macOS (or Linux).

brew.sh

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

 

npm 을 사용하기 위해 node 설치

$ brew update
$ brew uninstall node
$ brew install node
$ brew postinstall

 

npm 설치확인

$ npm --version

 

 

 

 

Yarn 설치하기

$ npm install --global yarn


/usr/local/bin/yarn -> /usr/local/lib/node_modules/yarn/bin/yarn.js
/usr/local/bin/yarnpkg -> /usr/local/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.22.4

 

 

2. React-Native 를 위한 2가지 방법

샘플 앱 실행을 위해서는 크게 2가지가 존재합니다.

 

1. CRNA (Create-react-native-app)를 이용하는 방법

Xcode나 android studio를 설치할 필요가 없는 방식으로 바로 실행해 보길 원하는 경우에 이용합니다.

이때 Expo 를 이용하면, android studio, Xcode 가 필요없이 개발 진행을 도와주고, Expo Clint로 테스트도 가능합니다.

 

2. React-native 명령어를 이용하는 방법
이전 react native를 사용하는 보통의 개발 방법입니다.
CRNA가 2017년 나왔으며 앞으로는 CRNA를 권장할 가능성이 있습니다.
react-native 명령어를 이용하는 방법은 iOS 개발을 위해 Mac이 꼭 필요합니다.

 

 

2-1. CRNA (Create-react-native-app)를 이용하는 경우, 설치

-- CRNA 설치

$ npm install -g create-react-native-app

-- 프로젝트를 생성합니다.

$ create-react-native-app 프로젝트명
$ cd 프로젝트 명
$ npm start

 

먄약 실행이 안된다면

Androi인 경우는 USB에 안드로이드 폰을 연결하세요.
https://developer.android.com/studio/run/device.html#developer-device-options
그리고 실행후에는 안드로이드 폰은 노트북과 같은 Wi-Fi에 같이 존재해야 합니다.

 

 

노드는 설치가 되어 있다면 아래  watchman 설치, 자세한 설명은 프로젝트 Readme.md에 나와있습니다.

$ brew install watchman
6. Readme.md 파일 확인

 

 

2-2. React-native 명령어를 이용하는 방법

-- react-native-cli 설치

$ npm install -g react-native-cli

-- react-native 를 설치하진 마세요.

$ react-native init 프로젝트명
$ cd 프로젝트명

$ react-native run-ios
또는 
$ react-native run-android

* npm install -g react-native  을 설치하지 마세요.

 

Error 발생시

처음에 언급한 getting-started Site에서 빠진 부분이 없는지 확인해야 됩니다.

 

iOS : Xcode -> Preferences -> Locations -> Command Line Tools 의 설정이 빠져있다면 설정해주세요.

Android: JDK 설치 유무확인, SDK Manager에서 필수 설치 미설치 여부 인해야 합니다.

 

테스트 버전정보

$ brew --version
Homebrew 2.4.2
Homebrew/homebrew-core (git revision 94f44; last commit 2020-06-30)

$ react-native --version
react-native-cli: 2.0.1
react-native: 0.62.2

$ yarn --version
1.22.4

$ create-react-native-app --version
3.5.0

$ node --version
v14.4.0

$ npm --version
6.14.4

 

+ Recent posts