美文网首页
vue项目实战(一)打包

vue项目实战(一)打包

作者: 领带衬有黄金 | 来源:发表于2019-08-14 16:53 被阅读0次

获取空项目
使用npm satrt 运行测试环境
使用npm build 获得生产环境文件夹->使用serve dist 运行项目(如果serve未安装,使用npm i serve -g)
在config/index.js中修改autoopenBrower:可以设置默认打开浏览器。
解决国内镜像很慢的问题:

国外镜像会很慢 
可用 get命令查看registry

npm config get registry
1
原版结果为

http://registry.npmjs.org

用set命令换成阿里的镜像就可以了


npm config set registry http://registry.npm.taobao.org

1. 开始建立一个开发环境

npm install -g vue-cli # 下载全局脚手架,只下载一次
vue init webpack my-project

cd my-project
npm install
npm run dev

2. 打包

npm run build
npm install -g serve  # 下载本地静态服务器,只下载一次
serve  dist # 启动打包过后的项目

2.1 使用tomcat运行项目

修改配置:webpack.prod.conf.js

output:{
        publicPath:'/打包文件夹的名称如:vue_demo/'
}

重新打包:npm run build
修改dist 文件夹为项目名称:xxxx
将xxxx拷贝到运行的tomcat的webapps目录中
访问:http://localhost:8080/xxxx/

在.eslintrc.js文件中进行代码检查的忽略处理

'indent': 'off', // 需要注释
'no-tabs': 'off'  //需要制表符

也可以直接在.eslintignore文件中进行文件检查的忽略
忽略一下文件检查,但一般最后都是要将js,和vue文件尽心检查的,为了代码规范

/build/
/config/
/dist/
/*.js
/test/unit/coverage/

*.js
*.vue
2.2 使用nginx部署项目

在nginx/conf中新建一个vhost文件夹并打开新文件 vue.conf,填入内容:

server
{
listen 8099;
server_name 192.168.0.155:8080;
index index.html index.htm index.php;
root /home/cykj/git_product/vue_product/dist;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
}

在nginx.conf的http中添加include vhost/*.conf;
然后将文件打包放在某个位置,在root中

相关文章

网友评论

      本文标题:vue项目实战(一)打包

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