【Vuejs】2023- Vue3 项目前端 CI/CD 体验
前端自习课
共 16784字,需浏览 34分钟
· 2024-04-20
1. 环境准备
➜ app-cicd node --version
v18.0.0
➜ app-cicd npm --version
9.6.6
2. 安装
2.1 初始化选项
项目初始化选择。
➜ app-cicd npm init vue@latest
Vue.js - The Progressive JavaScript Framework
✔ Project name: … app-cicd
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit Testing? … No / Yes
✔ Add an End-to-End Testing Solution? › No
✔ Add ESLint for code quality? … No / Yes
✔ Add Prettier for code formatting? … No / Yes
Scaffolding project in /Users/UserName/GitLabProjects/app-cicd...
Done. Now run:
cd app-cicd
npm install
npm run format
npm run dev
2.2 项目运行
按照命令行指示 npm run dev
。
➜ app-cicd npm run dev
> app-cicd@0.0.0 dev
> vite
VITE v4.3.5 ready in 1161 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h to show help
✘ [ERROR] Could not resolve "vue-demi"
node_modules/pinia/dist/pinia.mjs:6:206:
6 │ import { getCurrentInstance, inject, toRaw, watch, unref, markRaw, effectScope, ref, isVue2, isRef, isReactive, set, getCurrentScope, onScopeDispose, reactive, toRef, del, nextTick, computed, toRefs } from 'vue-demi';
╵ ~~~~~~~~~~
You can mark the path "vue-demi" as external to exclude it from the bundle, which will remove this
error.
出现以上错误修改,结合 vue-demi 配置说明[1] ,修改 package-lock.json,找到 vue-demi
"dependencies": {
"@vue/devtools-api": "^6.5.0",
"vue-demi": "latest" # “*” 改为 “latest”
},
"funding": {
"url": "https://github.com/sponsors/posva"
},
"peerDependencies": {
"@vue/composition-api": "^1.4.0",
"typescript": ">=4.4.4",
"vue": "^2.6.14 || ^3.2.0"
},
"peerDependenciesMeta": {
"@vue/composition-api": {
"optional": true
},
"typescript": {
"optional": true
}
},
# 新增配置
"devDependencies": {
"vue": "^3.0.0"
}
再 npm run dev
,成功!
➜ app-cicd npm run dev
> app-cicd@0.0.0 dev
> vite
VITE v4.3.5 ready in 296 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h to show help
浏览器访问 http://localhost:5173/[2]
3. 项目构建
因为要测试我们自己的网页,小小 build 一下。
➜ app-cicd npm run build
> app-cicd@0.0.0 build
> run-p type-check build-only
> app-cicd@0.0.0 build-only
> vite build
> app-cicd@0.0.0 type-check
> vue-tsc --noEmit -p tsconfig.vitest.json --composite false
vite v4.3.5 building for production...
✓ 39 modules transformed.
dist/assets/logo-277e0e97.svg 0.28 kB │ gzip: 0.20 kB
dist/index.html 0.42 kB │ gzip: 0.28 kB
dist/assets/AboutView-4d995ba2.css 0.09 kB │ gzip: 0.10 kB
dist/assets/index-4646de73.css 3.14 kB │ gzip: 1.08 kB
dist/assets/AboutView-b87b23ac.js 0.22 kB │ gzip: 0.20 kB
dist/assets/index-f6d09a3d.js 76.05 kB │ gzip: 30.49 kB
✓ built in 586ms
node_modules/@types/node/fs/promises.d.ts:199:52 - error TS1010:
199 * device. The specific implementation is o
Found 1 error in node_modules/@types/node/fs/promises.d.ts:199
ERROR: "type-check" exited with 2.
出现以上错误,按照提示,仔细查看发现注释符号未闭合。npm install --save @types/node
一下,再次 npm run build
,成功构建。
➜ app-cicd npm install --save @types/node
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
changed 1 package in 8s
111 packages are looking for funding
run `npm fund` for details
➜ app-cicd npm run build
> app-cicd@0.0.0 build
> run-p type-check build-only
> app-cicd@0.0.0 build-only
> vite build
> app-cicd@0.0.0 type-check
> vue-tsc --noEmit -p tsconfig.vitest.json --composite false
vite v4.3.5 building for production...
✓ 39 modules transformed.
dist/assets/logo-277e0e97.svg 0.28 kB │ gzip: 0.20 kB
dist/index.html 0.42 kB │ gzip: 0.28 kB
dist/assets/AboutView-4d995ba2.css 0.09 kB │ gzip: 0.10 kB
dist/assets/index-4646de73.css 3.14 kB │ gzip: 1.08 kB
dist/assets/AboutView-b87b23ac.js 0.22 kB │ gzip: 0.20 kB
dist/assets/index-f6d09a3d.js 76.05 kB │ gzip: 30.49 kB
✓ built in 578ms
4. 创建 Jenkinsfile
创建 Jenkinsfile 用于 Jenkins 流水线构建。
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
}
stages {
stage('Init') {
steps {
script {
checkout scmGit(
branches: [[name: 'master']],
userRemoteConfigs: [[credentialsId: 'ab8e0508-a9f3-4ff3-aa18-0afc27a4df08',url: 'http://192.168.2.159:9080/web/app-cicd.git']])
sh 'pwd && ls -l'
}
//
}
}
stage('Build') {
steps {
script {
echo "Build project"
sh 'node --version && npm --version'
sh 'npm install'
sh 'npm run build'
sh 'ls -l'
}
}
}
stage('Test') {
steps {
script {
echo "Test project"
}
}
}
stage('Deploy') {
steps {
script {
echo "Deploy project"
if(fileExists('/Users/username/apps/app-cicd')) {
sh 'rm -rf /Users/username/apps/app-cicd'
}
echo "Deploy project inited"
sh 'mv dist/ /Users/username/apps/app-cicd'
sh 'ls /Users/username/apps/app-cicd'
echo "Deploy project finished"
}
}
}
}
}
整体目录结构。
➜ app-cicd git:(master) ls -l
total 368
-rw-r--r-- 1 paxtonx staff 1432 5 13 11:26 Jenkinsfile
-rw-r--r-- 1 paxtonx staff 1763 5 12 23:56 README.md
drwxr-xr-x 5 paxtonx staff 160 5 13 02:39 dist
-rw-r--r-- 1 paxtonx staff 38 5 12 23:56 env.d.ts
-rw-r--r-- 1 paxtonx staff 331 5 12 23:56 index.html
drwxr-xr-x 335 paxtonx staff 10720 5 13 00:44 node_modules
-rw-r--r-- 1 paxtonx staff 140945 5 13 02:39 package-lock.json
-rw-r--r-- 1 paxtonx staff 1196 5 13 02:39 package.json
drwxr-xr-x 3 paxtonx staff 96 5 12 23:56 public
drwxr-xr-x 9 paxtonx staff 288 5 12 23:56 src
-rw-r--r-- 1 paxtonx staff 281 5 13 02:16 tsconfig.app.json
-rw-r--r-- 1 paxtonx staff 332 5 13 02:37 tsconfig.json
-rw-r--r-- 1 paxtonx staff 241 5 13 02:15 tsconfig.node.json
-rw-r--r-- 1 paxtonx staff 153 5 13 02:16 tsconfig.vitest.json
-rw-r--r-- 1 paxtonx staff 355 5 13 02:18 vite.config.ts
-rw-r--r-- 1 paxtonx staff 400 5 12 23:56 vitest.config.ts
5. 结语
将此项目推送到远程 GitLab 仓库中,备用。这里介绍了 Vue3 的一些基本使用,如项目安装、构建,然后介绍了 Jenkinsfile 的编写。时间关系呢,过程较为省略。毕竟大佬说 "Talk is cheap. Show me the code." - Linus Torvalds
6. 参考资料
www.jenkins.io/zh/doc/book…[3]
plugins.jenkins.io/git/#plugin…[4]
plugins.jenkins.io/nodejs/[5]
评论
五一抢票难,Github上这几个Python项目,你可以试试
又到五一长假啦(虽然其实就放了1天),大家是打算家里蹲or出去玩,又或者是在公司加班呢...今天给大家介绍三个和12306相关的项目,看看你是否用得上。/01/ py12306py12306购票助手,顾名思义,12306买票的~需要在python 3.6以上版本运行程序。1. 安装依赖gi
Crossin的编程教室
0
教你基于 Jenkins 搭建一套 CI/CD 系统
原文链接:https://mp.weixin.qq.com/s/KVc4IFky1z7kZn-7bz79DQ一、CI/CD环境介绍本次要实现如下效果,开发人员完成功能开发并提交代码到gitlab仓库,jenkins自动完成拉取代码、编译构建、代码扫描(sonarqube)、打
码农编程进阶笔记
0
大量 Java 开源项目停更...
点击关注公众号,Java 干货及时推送↓推荐阅读:投了 100 多份简历后…出品 | OSC开源社区(ID:oschina2013)Sonatype 发布了最新的一份《软件供应链状况》报告,深入探讨了如何在充满选择的世界中定义更好的软件,并探讨人工智能 (AI) 对软件开发的深远
Java技术栈
0
为什么我们公司还在用 Python 开发项目?
作者:哇哒嘻哇https://www.zhihu.com/question/278798145/answer/3416549119最近几年里,经常看到某些曾重度使用 Python 的大公司迁移成其它语言技术栈,但是,那些小公司/小团队的情况如何呢?一直很想了解那些仍在坚持使用 Python,且支撑业
机器学习算法与Python实战
0
LangChain又上新了!LangChain项目贡献者@莫尔索新书重磅上市
在 AI 领域,每天都有新技术和框架出现,作为一个开源框架,LangChain 提供了构建基于大模型的 AI 应用所需的模块和工具,大大降低了 AI 应用开发的门槛,使得任何人都可以基于 GPT-4 等大模型构建自己的创意应用。LangChain 框架的爆火LangChain 作为开源项目首次进入公
机器学习实验室
0
只写后台管理的前端要怎么提升自己
大厂技术 高级前端 Node进阶点击上方 程序员成长指北,关注公众号回复1,加入高级Node交流群本人写了五年的后台管理。每次面试前就会头疼,因为写的页面除了表单就是表格。抱怨过苦恼过也后悔过(虽然我现在已经心安理得的摆烂),但是站在现在的时间点
程序员成长指北
1
三年前端还不会配置Nginx,被老板打了,今天一口气学完
大厂技术 高级前端 Node进阶点击上方 程序员成长指北,关注公众号回复1,加入高级Node交流群引言先来看看为何需要做请求负载。 早期的业务都是基于单体节点部署,由于前期访问流量不大,因此单体结构也可满足需求,但随着业务
程序员成长指北
4
面试了一个字节出来的前端女生,她太太太厉害了
最近有个老同学进了某大厂—— 高级前端工程师,拿了45K*16薪!马上找他要来了几套高质量内部资料。既是高频真题,也是一套前端进阶学习宝典。几乎满足各级前端工程师的需求,内容涵盖了Html、Css、Javascript、vue、React、小程序、算法等等。实战代码清晰,解析也十分全面。足足有15套
java团长
0