chore(@vant/cli): remove build --watch option

This commit is contained in:
chenjiahan
2021-09-07 14:15:45 +08:00
parent 2dd7e853d6
commit cb0fb5a9e0
5 changed files with 4 additions and 37 deletions

View File

@@ -1,10 +1,9 @@
import execa from 'execa';
import chokidar from 'chokidar';
import { join, relative } from 'path';
import { remove, copy, readdirSync, existsSync } from 'fs-extra';
import { clean } from './clean';
import { CSS_LANG } from '../common/css';
import { ora, consola, slimPath } from '../common/logger';
import { ora, consola } from '../common/logger';
import { installDependencies } from '../common/manager';
import { compileJs } from '../compiler/compile-js';
import { compileSfc } from '../compiler/compile-sfc';
@@ -181,44 +180,13 @@ async function runBuildTasks() {
consola.success('Compile successfully');
}
function watchFileChange() {
consola.info('Watching file changes...');
chokidar.watch(SRC_DIR).on('change', async (path) => {
if (isDemoDir(path) || isTestDir(path)) {
return;
}
const spinner = ora('File changed, start compilation...').start();
const esPath = path.replace(SRC_DIR, ES_DIR);
const libPath = path.replace(SRC_DIR, LIB_DIR);
try {
await copy(path, esPath);
await copy(path, libPath);
await compileFile(esPath);
await compileFile(libPath);
await genStyleDepsMap();
genComponentStyle({ cache: false });
spinner.succeed('Compiled: ' + slimPath(path));
} catch (err) {
spinner.fail('Compile failed: ' + path);
console.log(err);
}
});
}
export async function build(cmd: { watch?: boolean } = {}) {
export async function build() {
setNodeEnv('production');
try {
await clean();
await installDependencies();
await runBuildTasks();
if (cmd.watch) {
watchFileChange();
}
} catch (err) {
consola.error('Build failed');
process.exit(1);