美文网首页程序员
浅谈vue cli2 与 vue cli3

浅谈vue cli2 与 vue cli3

作者: 没事举个栗子看看 | 来源:发表于2020-04-27 09:36 被阅读0次

本来打算自己尝试学学做npm包时,遇到了下面的问题。

PS F:\demo> vue create mynpmdemo

  vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6.
  You may want to run the following to upgrade to Vue CLI 3:

  npm uninstall -g vue-cli
  npm install -g @vue/cli

这段的意思是要先卸载vue cli2,然后重新安装vue cli 3。那么究竟vue cli2 与 vue cli3有什么区别呢?
首先先查看下我们本地的vue版本

vue -V

1.创建文件

vue create 进入工程文件夹,创建项目  //3.0
vue init webpack  //2.0

2.启动项目

npm run serve  //3.0启动
npm run dev  //2.0启动
//因为package.json中的"scripts"对象中的名字变了,所以启动命令也就变了,如果不习惯也可以手动改回去

3.目录结构不一致
4.配置端口号

//2.0中在/config/index.js中设置
//3.0中需要在根目录下创建一个vue.config.js文件.
module.exports = {
    baseUrl: process.env.NODE_ENV === 'production' ? '/online/' : '/',
    // outputDir: 在npm run build时 生成文件的目录 type:string, default:'dist'
    // outputDir: 'dist',
    // pages:{ type:Object,Default:undfind } 
    devServer: {
        port: 8888, // 端口号
        host: 'localhost',
        https: false, // https:{type:Boolean}
        open: true, //配置自动启动浏览器
        // proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
        proxy: {
            '/api': {
                target: '<url>',
                ws: true,
                changeOrigin: true
            },
            '/foo': {
                target: '<other_url>'
            }
        },  // 配置多个代理
    }

5.待补充。。。

相关文章

网友评论

    本文标题:浅谈vue cli2 与 vue cli3

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