VueJS project setting - TheOpenCloudEngine/uEngine-cloud GitHub Wiki

VueJS Basics μ—μ„œ κΈ°λ³Έ VueJS λ₯Ό html 파일둜 λ§Œλ“€μ–΄μ„œ μ‚¬μš©ν•˜λŠ” 법을 μ΅ν˜”λ‹€.
κ·ΈλŸ¬λ‚˜ μ‹€μ œλ‘œ ν”„λ‘œμ νŠΈλ₯Ό ν•˜κΈ° μœ„ν•΄μ„œλŠ” ν”„λ ˆμž„μ›Œν¬ ν˜•μ‹μœΌλ‘œ ν”„λ‘œμ νŠΈλ₯Ό κ΅¬μ„±ν•΄μ•Όν•œλ‹€.
μ—¬κΈ°μ„œλŠ” vue-cliλ₯Ό ν†΅ν•˜μ—¬ κΈ°λ³Έν™˜κ²½ μ…‹νŒ… 및 ν”„λ ˆμž„μ›Œν¬ ꡬ쑰λ₯Ό μ‚΄νŽ΄λ³΄κ² λ‹€.

IDE λ₯Ό μ‚¬μš©ν•˜μ—¬ ν”„λ‘œμ νŠΈλ₯Ό μƒμ„±ν•˜λ €λ©΄ npm install vue λͺ…λ ΉμœΌλ‘œ vueλ₯Ό μ„€μΉ˜ν• μˆ˜μžˆλ‹€.
NPM 은 java 둜 치면 maven 같은 nodejs 의 λͺ¨λ“ˆλ“€μ˜ 집합이닀.
CLI λŠ” Command line interface 의 μ•½μ–΄λ‘œ 터미널을 ν†΅ν•˜μ—¬ μ‚¬μš©μžμ™€ 컴퓨터가 μƒν˜Έμž‘μš©ν•˜λŠ”
방식을 λœ»ν•œλ‹€.

vue-cli μ„€μΉ˜

$ npm install -g vue-cli
$ vue list
  β˜…  browserify - A full-featured Browserify + vueify setup with hot-reload, linting & unit testing.
  β˜…  browserify-simple - A simple Browserify + vueify setup for quick prototyping.
  β˜…  pwa - PWA template for vue-cli based on the webpack template
  β˜…  simple - The simplest possible Vue setup in a single HTML file
  β˜…  webpack - A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.
  β˜…  webpack-simple - A simple Webpack + vue-loader setup for quick prototyping.

-g μ˜΅μ…˜μ€ κΈ€λ‘œλ²Œ μ „μ—­μœΌλ‘œ λͺ¨λ“ˆμ„ μ„€μΉ˜ν•˜λΌλŠ” μ˜λ―Έμ΄λ‹€.
vue list λ₯Ό ν†΅ν•˜μ—¬ vue μ—μ„œ μ œκ³΅ν•˜λŠ” ν…œν”Œλ¦Ώμ„ 확인 ν•  μˆ˜μžˆλ‹€.

webpack : ν”„λ‘œμ νŠΈμ˜ ꡬ쑰λ₯Ό λΆ„μ„ν•˜κ³  μžλ°”μŠ€ν¬λ¦½νŠΈ λͺ¨λ“ˆμ„ λΉ„λ‘―ν•œ κ΄€λ ¨ λ¦¬μ†ŒμŠ€λ“€μ„ 찾은 λ‹€μŒ 이λ₯Ό λΈŒλΌμš°μ €μ—μ„œ μ΄μš©ν•  수 μžˆλŠ” λ²ˆλ“€λ‘œ λ¬Άκ³  νŒ¨ν‚Ήν•˜λŠ” λͺ¨λ“ˆ λ²ˆλ“€λŸ¬(Module bundler)λ‹€.
μ°Έκ³  : μ›ΉνŒ©μ˜ κΈ°λ³Έ κ°œλ…
browserify : μ„œλ²„μ‚¬μ΄λ“œ ν™˜κ²½μ—μ„œ μ‚¬μš©λ˜λŠ” CommonJS ν˜•μ‹μ˜ require('modules') μ½”λ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ μ˜μ‘΄μ„± 관리λ₯Ό ν•  수 μžˆμ„ 뿐만 μ•„λ‹ˆλΌ, ν΄λΌμ΄μ–ΈνŠΈ μ‚¬μ΄λ“œ ν™˜κ²½μ—μ„œλ„ μ‚¬μš©ν•  수 μžˆλ„λ‘ ν•œλ° λ¬Άμ–΄μ£ΌλŠ”(Bundle) μœ μš©ν•œ νˆ΄μ΄λ‹€. 즉, Node.js와 같은 ν˜•μ‹μ„ μ›Ή λΈŒλΌμš°μ €μ—μ„œλ„ μ‹€ν–‰κ°€λŠ₯ν•˜κ²Œ λ§Œλ“€μ–΄ μ€€λ‹€.

μ„€λͺ…을 보면 webpack 이 browserify λ₯Ό ν¬ν•¨ν•˜λŠ” κ°œλ…μ΄κ³ , 관리가 νŽΈν•˜κΈ° λ•Œλ¬Έμ— 많이 쓰인닀.
이제 webpack 으둜 vue project λ₯Ό μƒμ„±ν•˜μ—¬ λ³Έλ‹€.

vue project 생성

## vue init <template-name> <project-name>
$ vue init webpack vue-webpack-project

? Project name vue-webpack-project
? Project description A Vue.js project
? Author kimscott <[email protected]>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests Yes
? Pick a test runner jest
? Setup e2e tests with Nightwatch? Yes
? Should we run `npm install` for you after the project has been created? (recommended) npm

cli 둜 μ„€μΉ˜μ‹œ μ—¬λŸ¬κ°€μ§€ μ˜΅μ…˜λ“€μ΄ λ‚˜μ˜¨λ‹€. ESLint λŠ” μ½”λ“œμ˜ λ£° μ„€μ •μœΌλ‘œ μ˜€νƒ€λ‚˜ μž‘μ„±μ˜€λ₯˜λ“±μ„ νŒŒμ•…ν•΄μ€€λ‹€.
κ·Έ 외에 ν…ŒμŠ€νŠΈ λͺ¨λ“ˆμ„ μ‚¬μš©ν• μ§€λ“±μ˜ μ…‹νŒ…κ³Ό npm install κΉŒμ§€ 할지 μ—¬λΆ€λ₯Ό λ¬»λŠ”λ‹€.

ν”„λ‘œμ νŠΈ ꡬ쑰 확인

$ cd vue-webpack-project
## ν•„μš”ν•œ λͺ¨λ“ˆλ“€ install
$ npm install

μ£Όμš” νŒŒμΌλ“€μ„ μ‚΄νŽ΄λ³΄λ©΄
index.html : 말이 ν•„μš”μ—†λ‹€μ‹œν”Ό 졜초 μ§„μž…μ μ΄λ‹€.
package.json : npm을 μ„€μ •ν•˜λŠ” 역할을 ν•œλ‹€. npm install μ‹œ package.json 파일의 dependencies, devDependencies 에 μ„€μ •ν•œ λͺ¨λ“ˆλͺ…κ³Ό 버전을 ν™•μΈν•˜λ©΄μ„œ μ„€μΉ˜λ₯Ό ν•œλ‹€.
node_modules : npm install ν›„ μƒμ„±λ˜λŠ” ν΄λ”λ‘œ nodejs λͺ¨λ“ˆλ“€μ„ λͺ¨μ•„λ†“λŠ”λ‹€. μš©λŸ‰μ΄ μ»€μ„œ ν˜•μƒκ΄€λ¦¬μ—μ„œ μ œμ™Έμ‹œν‚¨λ‹€.
build : npm build μ‹œ ν•„μš”ν•œ νŒŒμΌλ“€μ„ κ΄€λ¦¬ν•œλ‹€.
config : μ„€μ •νŒŒμΌλ“€μ„ 관리
src : 개발 μ½”λ“œκ°€ λ“€μ–΄κ°„λ‹€.
static : static 으둜 관리할 js, css νŒŒμΌμ΄λ‚˜ image νŒŒμΌλ“€μ„ λ„£λŠ” 폴더
dist : npm build ν›„ μƒμ„±λ˜λŠ” 폴더이닀. μƒμš©λ°°ν¬μ‹œ ν•΄λ‹Ή ν΄λ”μ˜ λ‚΄μš©μ„ λ°°ν¬ν•˜λ©΄ λœλ‹€.

npm 섀정을 κ΄€λ¦¬ν•˜λŠ” package.json νŒŒμΌμ„ μž μ‹œ μ‚΄νŽ΄λ³΄λ©΄

"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "unit": "jest --config test/unit/jest.conf.js --coverage",
    "e2e": "node test/e2e/runner.js",
    "test": "npm run unit && npm run e2e",
    "lint": "eslint --ext .js,.vue src test/unit test/e2e/specs",
    "build": "node build/build.js"
  }

μœ„μ™€κ°™μ΄ μ‹€ν—Ή λͺ…λ Ήμ–΄ 듀을 λͺ¨μ•„ λ†“μ•˜λ‹€.
λ‘œμ»¬μ„œλ²„λ‘œ νŽ˜μ΄μ§€λ₯Ό μ‹€ν–‰μ‹œν‚€λ €λ©΄ npm run dev λ₯Ό cli에 쳐도 λ˜μ§€λ§Œ, npm start 라고 쳐도
μœ„μ˜ scripts λ₯Ό ν•΄μ„ν•˜μ—¬ 싀행을 μ‹œμΌœμ€€λ‹€.

devDependencies λ₯Ό μ‚΄νŽ΄λ³΄λ©΄ "webpack": "^3.6.0" 처럼 ^ λŠ” Caret Ranges 둜
[major, minor, patch] 의 minor 버전뢀터 major λ²„μ „κΉŒμ§€λ§Œ ν—ˆμš©ν•œλ‹€λŠ” μ˜λ―Έμ΄λ‹€.
"3.6.0" <= "^3.6.0" < "4.0.0"
μ‹€μ œ ν”„λ‘œμ νŠΈμ—μ„œλŠ” "webpack": "3.6.0" 처럼 μ •ν™•ν•œ 버전을 fixν•΄μ„œ μ‚¬μš©ν•˜λŠ”κ±Έ μΆ”μ²œν•œλ‹€.

devDependencies 의 λͺ¨λ“ˆλ“€μ€‘ babel 은 ES6 문법을 μ‚¬μš©ν•˜κΈ° μœ„ν•œ λͺ¨λ“ˆμ΄λ‹€.

ν”„λ‘œμ νŠΈ μ‹€ν–‰

$ npm run dev
Your application is running here: http://localhost:8080         

ν”„λ‘œμ νŠΈλ₯Ό κ΅¬λ™μ‹œν‚€λ©΄ 둜컬 μ„œλ²„λ₯Ό μƒμ„±ν•˜λ©° http://localhost:8080 λ₯Ό ν†΅ν•˜μ—¬ λΈŒλΌμš°μ €μ—μ„œ 접근이 κ°€λŠ₯ν•˜λ‹€.
portλ₯Ό λ³€κ²½μ‹œν‚€λ €λ©΄ config/index.js νŒŒμΌμ—μ„œ 변경을 ν•˜μ—¬ μ£Όλ©΄ λœλ‹€.

⚠️ **GitHub.com Fallback** ⚠️