diff --git a/package.json b/package.json index c8ce820897970f4068e4b2b7b9ed2f3b31eda252..420f740c49e966d7dc32e86702413b78d9b331d1 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@vue/test-utils": "^2.3.2", "@vue/tsconfig": "^0.4.0", "autoprefixer": "^10.4.14", + "cross-spawn": "^7.0.3", "envfile": "^6.18.0", "eslint": "^8.39.0", "eslint-plugin-vue": "^9.11.0", @@ -45,7 +46,6 @@ "rollup-plugin-external-globals": "^0.8.0", "rollup-plugin-visualizer": "^5.9.0", "sass": "^1.63.5", - "shelljs": "^0.8.5", "typescript": "~5.0.4", "vite": "^4.3.9", "vite-plugin-compression": "^0.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a1e3b68ad5173e10164687318d97c84ef2b95753..3bcb785207fd88d580a8eeafeb27040f4b089cb7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -61,6 +61,9 @@ devDependencies: autoprefixer: specifier: ^10.4.14 version: registry.npmmirror.com/autoprefixer@10.4.14(postcss@8.4.23) + cross-spawn: + specifier: ^7.0.3 + version: registry.npmmirror.com/cross-spawn@7.0.3 envfile: specifier: ^6.18.0 version: registry.npmmirror.com/envfile@6.18.0 @@ -91,9 +94,6 @@ devDependencies: sass: specifier: ^1.63.5 version: registry.npmmirror.com/sass@1.63.5 - shelljs: - specifier: ^0.8.5 - version: registry.npmmirror.com/shelljs@0.8.5 typescript: specifier: ~5.0.4 version: registry.npmmirror.com/typescript@5.0.4 @@ -3577,13 +3577,6 @@ packages: side-channel: registry.npmmirror.com/side-channel@1.0.4 dev: true - registry.npmmirror.com/interpret@1.4.0: - resolution: {integrity: sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/interpret/-/interpret-1.4.0.tgz} - name: interpret - version: 1.4.0 - engines: {node: '>= 0.10'} - dev: true - registry.npmmirror.com/is-array-buffer@3.0.2: resolution: {integrity: sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/is-array-buffer/-/is-array-buffer-3.0.2.tgz} name: is-array-buffer @@ -4755,15 +4748,6 @@ packages: picomatch: registry.npmmirror.com/picomatch@2.3.1 dev: true - registry.npmmirror.com/rechoir@0.6.2: - resolution: {integrity: sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/rechoir/-/rechoir-0.6.2.tgz} - name: rechoir - version: 0.6.2 - engines: {node: '>= 0.10'} - dependencies: - resolve: registry.npmmirror.com/resolve@1.22.2 - dev: true - registry.npmmirror.com/regenerator-runtime@0.13.11: resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz} name: regenerator-runtime @@ -5030,18 +5014,6 @@ packages: version: 1.8.1 dev: true - registry.npmmirror.com/shelljs@0.8.5: - resolution: {integrity: sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/shelljs/-/shelljs-0.8.5.tgz} - name: shelljs - version: 0.8.5 - engines: {node: '>=4'} - hasBin: true - dependencies: - glob: registry.npmmirror.com/glob@7.2.3 - interpret: registry.npmmirror.com/interpret@1.4.0 - rechoir: registry.npmmirror.com/rechoir@0.6.2 - dev: true - registry.npmmirror.com/side-channel@1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/side-channel/-/side-channel-1.0.4.tgz} name: side-channel diff --git a/src/App.vue b/src/App.vue index d255d647d183bf142abcfa73b20332755a4147d1..470fa540c9902bc412348d7f36dc0713faed1a57 100644 --- a/src/App.vue +++ b/src/App.vue @@ -41,4 +41,6 @@ - + diff --git a/src/main.ts b/src/main.ts index 9e264b361607264ca4436b5a2d3c1a308ac8ef41..267ddb1849f59e9188e8708b0f7c014b617464e3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,3 @@ -import './assets/css/main.scss' - import { createApp } from 'vue' import App from './App.vue' import { createPinia } from 'pinia' diff --git a/start/index.js b/start/index.js index 27d8efc8853b1a9a0d6ae8a242478cd0921fbc2d..8f8c8a40c3a539b11135d6c75a2a04d23d33f375 100644 --- a/start/index.js +++ b/start/index.js @@ -1,8 +1,9 @@ /* * @Description: 该文件用于调试运行和打包的脚本 */ -const { getEnvShell } = require('./utils') -const shell = require('shelljs') + +const { spawn } = require('cross-spawn') +const { getEnvShell } = require('./utils.js') const inquirer = require('inquirer') /** 打包之后预览命令 */ @@ -37,8 +38,14 @@ async function checkList() { return commands[prompt.mode][prompt.environment] } -/** 运行脚本 */ +/** 运行脚本: https://www.npmjs.com/package/cross-spawn */ checkList().then((command) => { - console.log('command: ', command) - shell.exec(command) + const commands = command.split('&&').map((item) => item.trim()) + const children = commands.map((item) => item.split(' ')) + // 这里运行的pnpm是根据你的项目中的package.json中的scripts来决定的 + children.forEach((child) => { + spawn.sync('pnpm', child, { + stdio: 'inherit' + }) + }) }) diff --git a/start/utils.js b/start/utils.js index 023ca355b86f28625c4874ec8ee209de6a7a0680..1878b9e06a4363169c5fe25dc9ac55ba58f0aa76 100644 --- a/start/utils.js +++ b/start/utils.js @@ -2,7 +2,7 @@ * @Description: 工具库 */ const path = require('path') -const fs = require('fs'); +const fs = require('fs') const { parse } = require('envfile') /** @@ -18,9 +18,9 @@ function getPathEnvs() { fs.readdir(directory, function (err, files) { if (err) { resolve(envs) - return; + return } - files.forEach(fileName => { + files.forEach((fileName) => { // 如果fileName是以.env.开头的字符串 if (`${fileName}`.indexOf(firstName) === 0) { envs.push({ @@ -41,26 +41,25 @@ function getPathEnvs() { /** 获取所有配置的脚本 */ async function getEnvShell() { /** 类型检查命令 */ - const type_check = 'vue-tsc --noEmit -p tsconfig.vitest.json --composite false' + const type_check = `vue-tsc --noEmit -p tsconfig.vitest.json --composite false` const envs = await getPathEnvs() const shellSet = { commands: { - debug: { }, - build: { } + debug: {}, + build: {} }, environment: [] } - envs.forEach((item => { - const parsedFile = parse(fs.readFileSync(item.path, 'utf-8')); + envs.forEach((item) => { + const parsedFile = parse(fs.readFileSync(item.path, 'utf-8')) shellSet.environment.push({ - name: parsedFile.VITE_APP_ENVNAME, - value: item.mode + name: parsedFile.VITE_APP_ENVNAME, + value: item.mode }) shellSet.commands.debug[item.mode] = `vite --mode ${item.mode}` shellSet.commands.build[item.mode] = `${type_check} && vite build --mode ${item.mode}` - })) - - return shellSet; + }) + return shellSet } module.exports = { diff --git a/viteConfig/index.ts b/viteConfig/index.ts index 54bc8d540a8b3671cbfbce4046d18f204dd2588e..2a93fe436cf3f75638b84e6e2728d911128accf5 100644 --- a/viteConfig/index.ts +++ b/viteConfig/index.ts @@ -40,7 +40,7 @@ export default defineConfig((conf: ConfigEnv) => { ], resolve: { alias: { - '@': path.resolve('/src') + '@': path.resolve('./src') } }, /** 打包配置 */