From cb0fb5a9e0d8615b50dc2931bca7269e43f30730 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Tue, 7 Sep 2021 14:15:45 +0800 Subject: [PATCH] chore(@vant/cli): remove build --watch option --- packages/vant-cli/changelog.md | 1 + packages/vant-cli/package.json | 1 - packages/vant-cli/src/bin.ts | 1 - packages/vant-cli/src/commands/build.ts | 36 ++----------------------- packages/vant-cli/yarn.lock | 2 +- 5 files changed, 4 insertions(+), 37 deletions(-) diff --git a/packages/vant-cli/changelog.md b/packages/vant-cli/changelog.md index 5a492d912..b683751d0 100644 --- a/packages/vant-cli/changelog.md +++ b/packages/vant-cli/changelog.md @@ -7,6 +7,7 @@ - 使用 vite 代替 webpack 进行构建 - 站点构建产物的目录由 `site` 调整为 `site-dist` - 不再支持 webpack.config.js 配置文件 +- 不再支持 build 命令的 --watch 参数 - 不再内置 babel-plugin-import 插件 ## v4.0.0-beta.1 diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index 6ca142d8f..752467e6a 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -53,7 +53,6 @@ "@vue/test-utils": "2.0.0-rc.6", "autoprefixer": "^10.3.1", "babel-jest": "^27.0.6", - "chokidar": "^3.5.2", "clean-css": "^5.1.5", "commander": "^8.1.0", "consola": "^2.15.3", diff --git a/packages/vant-cli/src/bin.ts b/packages/vant-cli/src/bin.ts index dc017d9b0..82d4cbbc4 100644 --- a/packages/vant-cli/src/bin.ts +++ b/packages/vant-cli/src/bin.ts @@ -53,7 +53,6 @@ program.command('clean').description('Clean all dist files').action(clean); program .command('build') .description('Compile components in production mode') - .option('--watch', 'Watch file change') .action(build); program diff --git a/packages/vant-cli/src/commands/build.ts b/packages/vant-cli/src/commands/build.ts index 9ec5b533a..824189114 100644 --- a/packages/vant-cli/src/commands/build.ts +++ b/packages/vant-cli/src/commands/build.ts @@ -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); diff --git a/packages/vant-cli/yarn.lock b/packages/vant-cli/yarn.lock index 955793b77..b90749329 100644 --- a/packages/vant-cli/yarn.lock +++ b/packages/vant-cli/yarn.lock @@ -2458,7 +2458,7 @@ chardet@^0.7.0: resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== -"chokidar@>=3.0.0 <4.0.0", chokidar@^3.5.2: +"chokidar@>=3.0.0 <4.0.0": version "3.5.2" resolved "https://registry.nlark.com/chokidar/download/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" integrity sha1-26OXb8rbAW9m/TZQIdkWANAcHnU=