feat(@vant/cli): add build.packageManager config

This commit is contained in:
chenjiahan 2021-11-09 10:33:19 +08:00
parent 08847af422
commit ecd2fb4f13
3 changed files with 18 additions and 7 deletions

View File

@ -180,6 +180,13 @@ module.exports = {
}; };
``` ```
### build.packageManager
- Type: `'npm' | 'yarn' | 'pnpm'`
- Default: `undefined`
指定使用的包管理器。
### site.title ### site.title
- Type: `string` - Type: `string`

View File

@ -1,9 +1,7 @@
import fs from 'fs-extra';
import execa from 'execa'; import execa from 'execa';
import { join } from 'path';
import { consola } from './logger.js'; import { consola } from './logger.js';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { ROOT } from './constant.js'; import { getVantConfig } from './constant.js';
let hasYarnCache: boolean; let hasYarnCache: boolean;
@ -20,16 +18,21 @@ export function hasYarn() {
return hasYarnCache; return hasYarnCache;
} }
function isUsingPnpm() { function getPackageManager() {
const pnpmLock = join(ROOT, 'pnpm-lock.yaml'); const { build } = getVantConfig();
return fs.existsSync(pnpmLock);
if (build?.packageManager) {
return build?.packageManager;
}
return hasYarn() ? 'yarn' : 'npm';
} }
export async function installDependencies() { export async function installDependencies() {
consola.info('Install Dependencies\n'); consola.info('Install Dependencies\n');
try { try {
const manager = isUsingPnpm() ? 'pnpm' : hasYarn() ? 'yarn' : 'npm'; const manager = getPackageManager();
await execa(manager, ['install', '--prod=false'], { await execa(manager, ['install', '--prod=false'], {
stdio: 'inherit', stdio: 'inherit',

View File

@ -4,6 +4,7 @@ export default {
srcDir: 'src', srcDir: 'src',
namedExport: true, namedExport: true,
skipInstall: ['lazyload'], skipInstall: ['lazyload'],
packageManager: 'pnpm',
site: { site: {
publicPath: publicPath:
(typeof window === 'undefined' && process.env.PUBLIC_PATH) || (typeof window === 'undefined' && process.env.PUBLIC_PATH) ||