【VueJS+yarn】Vue CLI를 사용하여 vue 프로젝트 생성하기

14080 단어 YARNVue.jsvue-cli
평상시는 Angular입니다만, 최근에는 Vue가 좋기 때문에 우선 인스톨까지 해 보았습니다.

환경




Package
버전


yarn
v1.15.2

node.js
v12.3.1

Vue CLI
3.8.2


vue-cli 설치



yarn
$ yarn global add @vue/cli
yarn global v1.15.2
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
warning Your current version of Yarn is out of date. The latest version is "1.16.0", while you're on "1.15.2".
info To upgrade, run the following command:
$ brew upgrade yarn
success Installed "@vue/[email protected]" with binaries:
      - vue
✨  Done in 21.92s.


vue 프로젝트 만들기


  • vue create 에서 프로젝트 만들기

  • vue-cli
    vue create sample-vue-project
    
  • Manually select features 선택

  • vue-cli
    Vue CLI v3.8.2
    ? Please pick a preset: 
      default (babel, eslint) 
    ❯ Manually select features 
    
  • 여기에서 원하는 것을 자유롭게 선택합니다. 이번에는 PWA는 사용하지 않으므로 그 이외에 체크.
  • JS는 Typescript로 작성하고 싶습니다
  • 테스트도 한다
  • 이번에는 PWA는 사용하지 않는다


  • vue-cli
    ? Check the features needed for your project: 
     ◉ Babel
     ◉ TypeScript
     ◯ Progressive Web App (PWA) Support
     ◉ Router
     ◉ Vuex
     ◉ CSS Pre-processors
     ◉ Linter / Formatter
     ◉ Unit Testing
    ❯◉ E2E Testing
    
  • Class 구문을 사용하는 경우는 Y를 지정

  • vue-cli
    ? Use class-style component syntax? (Y/n) y
    
  • TypeScript와 Babel을 병용하는 경우는 Y를 지정

  • vue-cli
    ? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfi
    lls, transpiling JSX)? (Y/n) y
    
  • router에 히스토리 모드를 사용하는 경우는 Y를 지정

  • vue-cli
    ? Use history mode for router? (Requires proper server setup for index fallback 
    in production) (Y/n) y
    
  • CSS 유형 지정

  • vue-cli
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported 
    by default): 
      Sass/SCSS (with dart-sass) 
    ❯ Sass/SCSS (with node-sass) 
      Less 
      Stylus 
    
  • TypeScript를 사용하기 때문에 TSLint를 지정한다

  • vue-cli
    ? Pick a linter / formatter config: (Use arrow keys)
    ❯ TSLint 
      ESLint with error prevention only 
      ESLint + Airbnb config 
      ESLint + Standard config 
      ESLint + Prettier 
    
  • Lint를 실행할 타이밍을 지정합니다.

    vue-cli
    Pick additional lint features: (Press <space> to select, <a> to toggle all, <i
    > to invert selection)
    ❯◉ Lint on save
     ◯ Lint and fix on commit
    
  • Unit 테스트용 Package 선택
  • 이번에는 Mocha와 Chai를 지정


  • vue-cli
    ? Pick a unit testing solution: 
    ❯ Mocha + Chai 
      Jest 
    
  • E2E 테스트용 패키지 선택
  • 이번에는 크롬 용 Cypress를 지정


  • vue-cli
    ? Pick a E2E testing solution: 
    ❯ Cypress (Chrome only) 
      Nightwatch (Selenium-based) 
    
  • Babel, PostCSS, ESLint 등의 설정을 어디에 쓸지를 지정.
  • 이번은 package.json 에 남깁니다.


  • vue-cli
    ? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? 
      In dedicated config files 
    ❯ In package.json 
    
  • 지금까지 설정을 남기려면 Y를 지정하여 설정의 이름을 지정하십시오.

  • vue-cli
    ? Save this as a preset for future projects? Yes
    ? Save preset as: sample_project
    
  • package manager는 Yarn을 선택

  • vue-cli
    ? Pick the package manager to use when installing dependencies: (Use arrow keys)
    
    ❯ Use Yarn 
      Use NPM 
    
  • 선택이 끝나면 프로젝트가 생성됩니다.

  • vue-cli
    Vue CLI v3.8.2
    ✨  Creating project in /Users/******/vscode/sample-vue-project.
    🗃  Initializing git repository...
    ⚙  Installing CLI plugins. This might take a while...
    
    yarn install v1.15.2
    info No lockfile found.
    [1/4] 🔍  Resolving packages...
    
    
    
    success Saved lockfile.
    ✨  Done in 59.59s.
    🚀  Invoking generators...
    📦  Installing additional dependencies...
    [-/5] ⠁ waiting...
    yarn install v1.15.2
    [1/4] 🔍  Resolving packages...
    [2/4] 🚚  Fetching packages...
    [3/4] 🔗  Linking dependencies...
    [4/4] 🔨  Building fresh packages...
    success Saved lockfile.
    ✨  Done in 19.53s.
    ⚓  Running completion hooks...
    
    📄  Generating README.md...
    
    🎉  Successfully created project sample-vue-project.
    👉  Get started with the following commands:
    
     $ cd sample-vue-project
     $ yarn serve
    

    테스트 실행


  • 프로젝트 내에서 yarn serve 실행

  • vue-cli
    $ yarn serve
    yarn run v1.15.2
    $ vue-cli-service serve
     INFO  Starting development server...
    Starting type checking and linting service...
    Using 1 worker with 2048MB memory limit
     98% after emitting CopyPlugin                                                    
    
     DONE  Compiled successfully in 2404ms                                                                                                                                                                                                                           15:04:13
    
    Type checking and linting in progress...
    
      App running at:
      - Local:   http://localhost:8081/ 
      - Network: http://192.168.1.22:8081/
    
      Note that the development build is not optimized.
      To create a production build, run yarn build.
    
    No type errors found
    No lint errors found
    Version: typescript 3.5.1, tslint 5.17.0
    Time: 2896ms
    
  • http://localhost:8081/에 액세스하여 다음 화면이 나오면 완료



  • 최종 Package.json



    package.json
    {
      "name": "sample-vue-project",
      "version": "0.1.0",
      "private": true,
      "scripts": {
        "serve": "vue-cli-service serve",
        "build": "vue-cli-service build",
        "lint": "vue-cli-service lint",
        "test:e2e": "vue-cli-service test:e2e",
        "test:unit": "vue-cli-service test:unit"
      },
      "dependencies": {
        "core-js": "^2.6.5",
        "vue": "^2.6.10",
        "vue-class-component": "^7.0.2",
        "vue-property-decorator": "^8.1.0",
        "vue-router": "^3.0.3",
        "vuex": "^3.0.1"
      },
      "devDependencies": {
        "@types/chai": "^4.1.0",
        "@types/mocha": "^5.2.4",
        "@vue/cli-plugin-babel": "^3.8.0",
        "@vue/cli-plugin-e2e-cypress": "^3.8.0",
        "@vue/cli-plugin-typescript": "^3.8.0",
        "@vue/cli-plugin-unit-mocha": "^3.8.0",
        "@vue/cli-service": "^3.8.0",
        "@vue/test-utils": "1.0.0-beta.29",
        "chai": "^4.1.2",
        "node-sass": "^4.9.0",
        "sass-loader": "^7.1.0",
        "typescript": "^3.4.3",
        "vue-template-compiler": "^2.6.10"
      },
      "postcss": {
        "plugins": {
          "autoprefixer": {}
        }
      },
      "browserslist": [
        "> 1%",
        "last 2 versions"
      ]
    }
    

    좋은 웹페이지 즐겨찾기