美文网首页
vue-cli 3.x 安装使用

vue-cli 3.x 安装使用

作者: 孙_ | 来源:发表于2019-08-03 18:23 被阅读0次

    基础命令

    # 安装
    npm install -g @vue/cli
    
    # 检查是否安装成功
    vue -V
    
    # 新建项目
    vue create my-project
    
    # 项目启动
    npm run serve
    
    # 打包
    npm run build
    

    功能配置

    运行以下命令来创建一个新项目:

    vue create my-project
    

    你可以选默认的包含了基本的 Babel + ESLint 设置的 preset,也可以选“手动选择特性”来选取需要的特性(这里我们选择手动选择功能)

    Vue CLI v3.9.3
    ? Please pick a preset:
      default (babel, eslint)
    > Manually select features
    

    自定义功能配置 (按下空格选择或取消)

    Vue CLI v3.9.3
    ? Please pick a preset: Manually select features
    ? 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
    

    路由是否使用history模式(如果使用history模式,需要后台去配合)

    Vue CLI v3.9.3
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter
    ? Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) n
    

    选择CSS 预处理类型 (按自己习惯即可)

    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter
    ? Use history mode for router? (Requires proper server setup for index fallback in production) No
    ? 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
    

    选择Linter / Formatter规范类型 (按自己习惯即可)

    Vue CLI v3.9.3
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter
    ? Use history mode for router? (Requires proper server setup for index fallback in production) No
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Less
    ? Pick a linter / formatter config:
      ESLint with error prevention only
      ESLint + Airbnb config
    > ESLint + Standard config
      ESLint + Prettier
    

    选择检测的方式(保存的时候检测/提交的时候检测)

    Vue CLI v3.9.3
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter
    ? Use history mode for router? (Requires proper server setup for index fallback in production) No
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Less
    ? Pick a linter / formatter config: Standard
    ? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)
    >(*) Lint on save
     ( ) Lint and fix on commit
    

    选择 Babel, PostCSS, ESLint 等自定义配置的存放位置 (单独配置成文件/package.json中)

    Vue CLI v3.9.3
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter
    ? Use history mode for router? (Requires proper server setup for index fallback in production) No
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Less
    ? Pick a linter / formatter config: Standard
    ? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
    ? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? (Use arrow keys)
    > In dedicated config files
      In package.json
    

    是否保存刚刚这些配置 (按自己习惯即可)

    Vue CLI v3.9.3
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter
    ? Use history mode for router? (Requires proper server setup for index fallback in production) No
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Less
    ? Pick a linter / formatter config: Standard
    ? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
    ? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In dedicated config files
    ? Save this as a preset for future projects? (y/N) n
    

    然后自动下载依赖,下载完成会提示

    �  Successfully created project vue-study.
    �  Get started with the following commands:
    
     $ cd my-project
     $ npm run serve
    

    执行npm run serve命令,即可看到效果

    相关文章

      网友评论

          本文标题:vue-cli 3.x 安装使用

          本文链接:https://www.haomeiwen.com/subject/vuqsdctx.html