1、首先要安装node和npm或cnpm
//在容器里执行安装node v18.16.1:
apt update && apt install -y vim
apt install wget
wget https://nodejs.org/dist/v18.16.1/node-v18.16.1-linux-x64.tar.gz
tar -zxvf node-v18.16.1-linux-x64.tar.gz
vim /etc/profile
export PATH=/home/node-v18.16.1-linux-x64/bin:$PATH
source /etc/profile
node -v
//在容器里执行安装cnpm
apt-get update
apt-get install
npm config set strict-ssl false
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm config set strict-ssl true
二、
为了满足下面的install和build,提前在容器里面的jenkins的workspace的项目中执行
apt-get update
apt-get install
npm config set strict-ssl false
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm config set strict-ssl true
shell脚本如下:
echo "开始构建"
echo $USER
node -v
npm -v
cnpm install
cnpm run build
echo "完成构建"
三、最后安装nginx后配置conf如下:
server {
listen 80; # 监听80端口,对于HTTPS则为443
server_name 192.168.20.84; # 你的域名
root /var/www/zhyq; # Vue应用构建后的文件夹路径
index index.html; # 默认文档
location / {
try_files $uri $uri/ /index.html; # 用于支持基于HTML5 History API的路由
}
# 用于处理静态文件的过期时间,可根据需要调整
location ~* \.(?:css|js|jpg|jpeg|gif|png|ico|svg|woff2|woff|ttf|otf)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# 其他可能的配置,比如日志路径
access_log /var/log/nginx/vue-app-access.log;
error_log /var/log/nginx/vue-app-error.log;
}
四、重启nginx
systemctl reload nginx
完成