vue-cli4 快速搭建项目详解

1,229 阅读2分钟

搭建项目之前,请确认已经安装过node, npm, vue cli。

1.vue-cli安装 npm install vue-cli -g

2.vue-cli版本查看 查看vue版本:vue -V

3.依赖的node版本,Node.js 8.9以上

4.vue create project-one

5.选择Manually select features,进行手动配置

6.选择需要的配置项,通过上下箭头选择要配置的项,空格是选中,a是全选,i是反选

( ) Babel //转码器,可以将ES6代码转为ES5代码,从而在现有环境执行。

( ) TypeScript// TypeScript是一个JavaScript(后缀.js)的超集(后缀.ts)包含并扩展了 JavaScript 的语法,需要被编译输出为 JavaScript在浏览器运行

( ) Progressive Web App (PWA) Support// 渐进式Web应用程序

( ) Router // vue-router(vue路由)

( ) Vuex // vuex(vue的状态管理模式)

( ) CSS Pre-processors // CSS 预处理器(如:less、sass)

( ) Linter / Formatter // 代码风格检查和格式化(如:ESlint)

( ) Unit Testing // 单元测试(unit tests)

( ) E2E Testing // e2e(end to end) 测试

7.选择是否使用history router

hash模式和history模式,hash模式打包出来直接丢到服务器上直接使用,history模式需要服务器那边再进行配置

nginx配置:

    location / {
      try_files $uri $uri/ /index.html;
    }

8.选择css预处理器

node-sass是自动编译实时的,dart-sass需要保存后才会生效。

9.选择Eslint代码验证规则

提供一个插件化的javascript代码检测工具,ESLint + Prettier //使用较多

10.选择什么时候进行代码规则检验

    ( ) Lint on save // 保存就检测
    ( ) Lint and fix on commit // fix和commit时候检查

建议选择保存就检测,等到commit的时候,问题可能都已经积累很多了。

11.选择如何存放配置

    In dedicated config files // 独立文件放置
    In package.json // 放package.json里

12.是否保存当前配置,N不保存

13.等待创建项目

14.执行它给出的命令,可以直接访问了 npm run serve