diff --git a/packages/vant-cli/docs/config.md b/packages/vant-cli/docs/config.md index 6649503f4..34aecff15 100644 --- a/packages/vant-cli/docs/config.md +++ b/packages/vant-cli/docs/config.md @@ -180,6 +180,13 @@ module.exports = { }; ``` +### build.packageManager + +- Type: `'npm' | 'yarn' | 'pnpm'` +- Default: `undefined` + +指定使用的包管理器。 + ### site.title - Type: `string` diff --git a/packages/vant-cli/src/common/manager.ts b/packages/vant-cli/src/common/manager.ts index ceae224e2..e660b3c08 100644 --- a/packages/vant-cli/src/common/manager.ts +++ b/packages/vant-cli/src/common/manager.ts @@ -1,9 +1,7 @@ -import fs from 'fs-extra'; import execa from 'execa'; -import { join } from 'path'; import { consola } from './logger.js'; import { execSync } from 'child_process'; -import { ROOT } from './constant.js'; +import { getVantConfig } from './constant.js'; let hasYarnCache: boolean; @@ -20,16 +18,21 @@ export function hasYarn() { return hasYarnCache; } -function isUsingPnpm() { - const pnpmLock = join(ROOT, 'pnpm-lock.yaml'); - return fs.existsSync(pnpmLock); +function getPackageManager() { + const { build } = getVantConfig(); + + if (build?.packageManager) { + return build?.packageManager; + } + + return hasYarn() ? 'yarn' : 'npm'; } export async function installDependencies() { consola.info('Install Dependencies\n'); try { - const manager = isUsingPnpm() ? 'pnpm' : hasYarn() ? 'yarn' : 'npm'; + const manager = getPackageManager(); await execa(manager, ['install', '--prod=false'], { stdio: 'inherit', diff --git a/packages/vant/vant.config.mjs b/packages/vant/vant.config.mjs index 70e77c023..92a437cf3 100644 --- a/packages/vant/vant.config.mjs +++ b/packages/vant/vant.config.mjs @@ -4,6 +4,7 @@ export default { srcDir: 'src', namedExport: true, skipInstall: ['lazyload'], + packageManager: 'pnpm', site: { publicPath: (typeof window === 'undefined' && process.env.PUBLIC_PATH) ||