新增打包脚本
This commit is contained in:
parent
971f9a3e66
commit
450108d6ac
|
|
@ -5,7 +5,7 @@
|
|||
"scripts": {
|
||||
"dev": "vite",
|
||||
"preview": "vite preview --port 4173",
|
||||
"build": "vite build",
|
||||
"build": "node ./scripts/build.mjs",
|
||||
"type-check": "vue-tsc --noEmit",
|
||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
||||
},
|
||||
|
|
@ -42,6 +42,8 @@
|
|||
"consola": "^2.15.3",
|
||||
"eslint": "^8.5.0",
|
||||
"eslint-plugin-vue": "^9.0.0",
|
||||
"execa": "^6.1.0",
|
||||
"fs-extra": "^10.1.0",
|
||||
"postcss": "^8.4.14",
|
||||
"prettier": "^2.5.1",
|
||||
"sass": "^1.53.0",
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
#!/bin/bash
|
||||
# 文件原路径
|
||||
srcPath="./dist/"
|
||||
# 发布路径文件夹
|
||||
releasePath="../server/public/admin"
|
||||
|
||||
#删除发布目录下的mobile文件
|
||||
rm -r $releasePath
|
||||
echo "已删除 ==> $releasePath 下的目录文件"
|
||||
mkdir $releasePath
|
||||
echo "已新建 ==> $releasePath 目录"
|
||||
|
||||
# 复制打包目录内的文件到发布目录
|
||||
cp -r $srcPath/* $releasePath
|
||||
echo "已复制 $srcPath/* ==> $releasePath"
|
||||
|
||||
cp $releasePath/../favicon.ico $releasePath
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import { execaCommand } from 'execa'
|
||||
import path from 'path'
|
||||
import fsExtra from 'fs-extra'
|
||||
const { existsSync, remove, copy } = fsExtra
|
||||
const cwd = process.cwd()
|
||||
//打包发布路径,谨慎改动
|
||||
const releaseRelativePath = '../frontend'
|
||||
const distPath = path.resolve(cwd, 'dist')
|
||||
const releasePath = path.resolve(cwd, releaseRelativePath)
|
||||
|
||||
async function build() {
|
||||
await execaCommand('vite build', { stdio: 'inherit', encoding: 'utf-8', cwd })
|
||||
if (existsSync(releasePath)) {
|
||||
await remove(releasePath)
|
||||
}
|
||||
console.log(`文件正在复制 ==> ${releaseRelativePath}`)
|
||||
try {
|
||||
await copyFile(distPath, releasePath)
|
||||
} catch (error) {
|
||||
console.log(`\n ${error}`)
|
||||
}
|
||||
console.log(`文件已复制 ==> ${releaseRelativePath}`)
|
||||
}
|
||||
|
||||
function copyFile(sourceDir, targetDir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
copy(sourceDir, targetDir, (err) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
build()
|
||||
Loading…
Reference in New Issue