美文网首页前端我爱编程vue学习沉淀
vue-cli3.0-beta vue脚手架3.0的使用

vue-cli3.0-beta vue脚手架3.0的使用

作者: eks | 来源:发表于2018-04-13 11:24 被阅读2191次

    中文文档
    https://github.com/toBeTheLight/vue-cli-3.x-doc-cn/blob/dev/README.md
    在安装之前请装好nodeJs

    1.使用

    npm install -g @vue/cli
    # or
    yarn global add @vue/cli
    

    查看版本(是否安装成功):vue -V(大写的V)


    11576163-5ebc6d418467d0c4.png

    2.命令变化

      Commands:
    
        create [options] <app-name>      create a new project powered by vue-cli-service // 创建一个由vue-cli-service支持的新项目
        add <plugin> [pluginOptions]     install a plugin and invoke its generator in an already created project // 在已创建的项目中添加插件
        invoke <plugin> [pluginOptions]  invoke the generator of a plugin in an already created project // 在开发者模式下以零配置运行一个js或vue文件
        inspect [options] [paths...]     inspect the webpack config in a project with vue-cli-service // 在vue-cli-service的项目中检查webpack配置
        serve [options] [entry]          serve a .js or .vue file in development mode with zero config // 简单理解为开发环境下启动命令
        build [options] [entry]          build a .js or .vue file in production mode with zero config // 在生产模式下以零配置构建一个js或vue文件
        init <template> <app-name>       generate a project from a remote template (legacy API, requires @vue/cli-init) // 旧api 需要@vue/cli-init // 就是原来的vue-cli init <template> <app-name>
    

    3.创建一个项目
    新建文件夹,在该文件夹下打开命令窗口,输入以下命令,
    vue create project-name
    这时你会看见

    Vue CLI v3.0.0-beta.6
    ? Please pick a preset: (Use arrow keys)
    > xs-default (vue-router, vuex, stylus, babel, pwa, eslint, unit-jest) // 这是我运行过之后的默认设置,第一次执行create是没有的
      default (babel, eslint)
      Manually select features
    

    按键盘上下键选择默认(default)还是手动(Manually),如果选择default,一路回车执行下去就行了(注:现在vue-cli3.0默认使用yarn下载),这里我选择手动,


    11576163-5ce01980491220c1.png

    4.选择配置,这时你会看见一些选项,
    你要集成什么就选就行了,我这里选个我比较常用的(注:空格键是选中与取消,A键是全选)

    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: (Press <space> to select, <a> to toggle all, <i> to invert selection)
    >( ) TypeScript
     ( ) Progressive Web App (PWA) Support
     ( ) Router
     ( ) Vuex
     ( ) CSS Pre-processors
     ( ) Linter / Formatter
     ( ) Unit Testing
     ( ) E2E Testing
    
    11576163-6cbc16d02b36888b.png

    5.选择css预处理,这里我选择stylus

    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Router, Vuex, CSS Pre-processors, Linter, Unit
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default):
    > SCSS/SASS
      LESS
      Stylus
    
    J1WT6J2M@U9P~N}B%IMYN3O.png

    6.选择ESLint + Prettier

    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Router, Vuex, CSS Pre-processors, Linter, Unit
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Stylus
    ? Pick a linter / formatter config: (Use arrow keys)
    > ESLint with error prevention only
      ESLint + Airbnb config
      ESLint + Standard config
      ESLint + Prettier
    
    11576163-d296d46dc6ca8f36.png

    7.选择语法检查方式,这里我选择保存就检测

    Vue CLI v3.0.0-beta.6
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Router, Vuex, CSS Pre-processors, Linter, Unit
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Stylus
    ? Pick a linter / formatter config: Prettier
    ? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)
    >( ) Lint on save // 保存就检测
     ( ) Lint and fix on commit // fix和commit时候检查
    
    1.png

    8.选择单元测试

    Vue CLI v3.0.0-beta.6
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Router, Vuex, CSS Pre-processors, Linter, Unit
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Stylus
    ? Pick a linter / formatter config: Prettier
    ? Pick additional lint features: Lint on save
    ? Pick a unit testing solution: (Use arrow keys)
    > Mocha + Chai
      Jest
    
    2.png

    9.她会问你 ,把babel,postcss,eslint这些配置文件放哪,这里随便选,我选择放在独立文件夹

    Vue CLI v3.0.0-beta.6
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Router, Vuex, CSS Pre-processors, Linter, Unit
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Stylus
    ? Pick a linter / formatter config: Prettier
    ? Pick additional lint features: Lint on save
    ? Pick a unit testing solution: Jest
    ? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? (Use arrow keys)
    > In dedicated config files // 独立文件放置
      In package.json // 放package.json里
    
    3.png

    10.键入N不记录,如果键入Y需要输入保存名字,如第一步所看到的我保存的名字为xs-default

    Vue CLI v3.0.0-beta.6
    ? Please pick a preset: Manually select features
    ? Check the features needed for your project: Router, Vuex, CSS Pre-processors, Linter, Unit
    ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Stylus
    ? Pick a linter / formatter config: Prettier
    ? Pick additional lint features: Lint on save
    ? Pick a unit testing solution: Jest
    ? 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) // 是否记录一下以便下次继续使用这套配置
    

    11.确定后,等待下载依赖模块


    4.png

    12.装好后,启动

    cd vue-pro3.0-demo // 进入项目根目录
    yarn serve // 启动项目
    
    5.png

    13.项目目录,现在的目录是3.0的cli看上去简洁多了,去掉了2.0 build和config等目录


    )Y_Z_RSKOTQNM%5MAH55`A9.png

    14.修改端口,在根目录下创建vue.config.js

    ARAM73G_ZUA)9$HYSZJRFQG.png
    vue.config.js相关配置请参考 https://github.com/vuejs/vue-cli/blob/dev/docs/config.md
    在vue.config.js找到
    devServer: {
            open: process.platform === 'darwin',
            host: '0.0.0.0',
            port: 1234,
            https: false,
            hotOnly: false,
            // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#configuring-proxy
            proxy: null, // string | Object
            before: app => {}
        },
    
    6.png

    15.本文使用vue-cli3.0的入门使用,希望可以帮到刚更多的人。

    相关文章

      网友评论

      • 吕檀溪:在linux上安装了vue-cli3 ,vue提示无法找到vue命令
      • 把我推进深海的你真善良:可不可以发表一个 vue-cli3 引外部js的文档呀
        把我推进深海的你真善良:@我友几个逗逼 好的,谢谢
        eks:你是引包还是引js?引包的话必须要export才能import,引js直接在html中的script引如就行了
      • f2965a3cfdb3:发的官方的文档有什么用呢?
      • 232c8a42e903:build之后,生成的包中打开index.html文件,会出现css、js加载错误,请问应该怎么配置呢
        eks:你大概是配置的访问路径错了
      • 南蓝NL:链接进不去呢
        你的宇哥哥:https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-cli/config.md
        可能楼主换了一下目录
        eks:官方文档地址变更 https://github.com/vuejs/vue-docs-zh-cn
      • fffff0155ae0:我快要被逼疯了,vscode的右键里的格式化,保存格式化,还有这个vue-cli的保存格式化,3个3种格式,运行就一堆警告,都不知道怎么处理!!!!
        eks:@junwtsadadsd 你可以在vue.config.js中配置禁用eslint,module.exports={lintOnSave: false}
        想个名字好麻烦的:大概率是,你vs默认加了代码格式工具和eslint的风格不一样,当然会冲突报错 一大堆警告啦~~~
        eks:这个官方文档太少,我没研究过,我都是用webpack自己配置,你可以研究下webpack
      • 442de64c8b99:我想问一下,我在windows系统上创建项目的时候上下键选择的时候前面的光标没有移动,这个问题请问有碰到过吗
        a42a2b151741:windows里,git bash MINGW 按1,然后回车选中第一行,按2,然后回车,会选择第二行。多选,忘了。
        eks:用windows自带的cmd
      • yang_fy:请问vue.config.js里怎么配置压缩混淆代码呀?我以前是在plugins里配的第三方插件ParallelUglifyPlugin,现在换成vue.config.js不知道怎么办了。请问应该怎么配呀?谢谢!
        大辉_f873:@我友几个逗逼 插件配置并不在这个地方,文档上有的
        // vue.config.js
        module.exports = {
        configureWebpack: {
        plugins: [
        new MyAwesomeWebpackPlugin()
        ]
        }
        }

        附上链接https://cli.vuejs.org/zh/guide/webpack.html#%E7%AE%80%E5%8D%95%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F
        eks:vue.config.js下翻到最后可以看到
        // options for 3rd party plugins
        pluginOptions: {
        // ...
        }

      本文标题:vue-cli3.0-beta vue脚手架3.0的使用

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