weapp-vite 1.5.6 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import logger from "@weapp-core/logger";
3
3
  var logger_default = logger;
4
4
 
5
5
  // package.json
6
- var version = "1.5.6";
6
+ var version = "1.6.0";
7
7
 
8
8
  // src/constants.ts
9
9
  var VERSION = version;
@@ -14,7 +14,6 @@ var supportedCssLangs = ["wxss", "scss", "less", "sass", "styl"];
14
14
  import { createRequire } from "node:module";
15
15
  import process from "node:process";
16
16
  import { addExtension, defu, isObject as isObject2, objectHash, removeExtension } from "@weapp-core/shared";
17
- import { watch } from "chokidar";
18
17
  import fs6 from "fs-extra";
19
18
  import path5 from "pathe";
20
19
  import { build, loadConfigFromFile } from "vite";
@@ -22,15 +21,6 @@ import tsconfigPaths from "vite-tsconfig-paths";
22
21
 
23
22
  // src/defaults.ts
24
23
  var defaultExcluded = ["**/node_modules/**", "**/miniprogram_npm/**"];
25
- function getWeappWatchOptions() {
26
- return {
27
- // '**/*.{wxml,json,wxs}', '**/*.{png,jpg,jpeg,gif,svg,webp}',
28
- paths: [".env", ".env.*"],
29
- ignored: [
30
- ...defaultExcluded
31
- ]
32
- };
33
- }
34
24
 
35
25
  // src/plugins/index.ts
36
26
  import { fdir as Fdir } from "fdir";
@@ -269,7 +259,9 @@ function vitePluginWeapp(ctx, subPackageMeta) {
269
259
  const input = getInputOption([...entriesSet]);
270
260
  options.input = input;
271
261
  },
272
- async buildStart() {
262
+ async buildEnd() {
263
+ const watchFiles = this.getWatchFiles();
264
+ debug?.("watchFiles count: ", watchFiles.length);
273
265
  const { build: build2 } = configResolved;
274
266
  const ignore = [
275
267
  ...defaultExcluded,
@@ -391,10 +383,8 @@ function vitePluginWeapp(ctx, subPackageMeta) {
391
383
  // console.log(id)
392
384
  // },
393
385
  // 调试监听
394
- buildEnd() {
395
- const watchFiles = this.getWatchFiles();
396
- debug?.("watchFiles count: ", watchFiles.length);
397
- },
386
+ // buildEnd() {
387
+ // },
398
388
  generateBundle(_options, bundle) {
399
389
  const bundleKeys = Object.keys(bundle);
400
390
  for (const bundleKey of bundleKeys) {
@@ -458,7 +448,6 @@ var CompilerContext = class {
458
448
  projectConfig;
459
449
  mode;
460
450
  packageJson;
461
- fsWatcherMap;
462
451
  rollupWatcherMap;
463
452
  entriesSet;
464
453
  entries;
@@ -479,7 +468,6 @@ var CompilerContext = class {
479
468
  this.projectConfig = projectConfig;
480
469
  this.mode = mode;
481
470
  this.packageJson = packageJson;
482
- this.fsWatcherMap = /* @__PURE__ */ new Map();
483
471
  this.rollupWatcherMap = /* @__PURE__ */ new Map();
484
472
  this.subPackageMeta = {};
485
473
  this.entriesSet = /* @__PURE__ */ new Set();
@@ -526,31 +514,7 @@ var CompilerContext = class {
526
514
  process.env.NODE_ENV = "development";
527
515
  }
528
516
  const inlineConfig = this.getConfig();
529
- const getWatcher = (paths2, opts2, inlineConfig2) => {
530
- const watcher2 = watch(paths2, opts2);
531
- let isReady = false;
532
- watcher2.on("all", async (eventName, _p) => {
533
- if (isReady && (eventName === "add" || eventName === "change" || eventName === "unlink")) {
534
- await this.internalDev(inlineConfig2);
535
- }
536
- }).on("ready", async () => {
537
- await this.internalDev(inlineConfig2);
538
- isReady = true;
539
- });
540
- return watcher2;
541
- };
542
- const { paths, ...opts } = defu(
543
- inlineConfig.weapp?.watch,
544
- {
545
- ignored: [
546
- path5.join(this.mpDistRoot, "**")
547
- ],
548
- cwd: this.cwd
549
- },
550
- getWeappWatchOptions()
551
- );
552
- const watcher = getWatcher(paths, opts, inlineConfig);
553
- this.fsWatcherMap.set("/", watcher);
517
+ const watcher = await this.internalDev(inlineConfig);
554
518
  return watcher;
555
519
  }
556
520
  getConfig(subPackageMeta, ...configs) {
@@ -807,6 +771,9 @@ var CompilerContext = class {
807
771
  if (appEntryPath && await fs6.exists(appConfigFile)) {
808
772
  const config = await readCommentJson(appConfigFile);
809
773
  if (isObject2(config)) {
774
+ if (this.entriesSet.has(appEntryPath)) {
775
+ return;
776
+ }
810
777
  this.entriesSet.add(appEntryPath);
811
778
  const appEntry = {
812
779
  path: appEntryPath,
package/dist/cli.cjs CHANGED
@@ -34,7 +34,7 @@ var import_vite3 = require("vite");
34
34
  var import_weapp_ide_cli = require("weapp-ide-cli");
35
35
 
36
36
  // package.json
37
- var version = "1.5.6";
37
+ var version = "1.6.0";
38
38
 
39
39
  // src/constants.ts
40
40
  var VERSION = version;
@@ -45,7 +45,6 @@ var supportedCssLangs = ["wxss", "scss", "less", "sass", "styl"];
45
45
  var import_node_module = require("module");
46
46
  var import_node_process = __toESM(require("process"), 1);
47
47
  var import_shared2 = require("@weapp-core/shared");
48
- var import_chokidar = require("chokidar");
49
48
  var import_fs_extra6 = __toESM(require("fs-extra"), 1);
50
49
  var import_pathe5 = __toESM(require("pathe"), 1);
51
50
  var import_vite2 = require("vite");
@@ -53,15 +52,6 @@ var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
53
52
 
54
53
  // src/defaults.ts
55
54
  var defaultExcluded = ["**/node_modules/**", "**/miniprogram_npm/**"];
56
- function getWeappWatchOptions() {
57
- return {
58
- // '**/*.{wxml,json,wxs}', '**/*.{png,jpg,jpeg,gif,svg,webp}',
59
- paths: [".env", ".env.*"],
60
- ignored: [
61
- ...defaultExcluded
62
- ]
63
- };
64
- }
65
55
 
66
56
  // src/logger.ts
67
57
  var import_logger = __toESM(require("@weapp-core/logger"), 1);
@@ -304,7 +294,9 @@ function vitePluginWeapp(ctx, subPackageMeta) {
304
294
  const input = getInputOption([...entriesSet]);
305
295
  options.input = input;
306
296
  },
307
- async buildStart() {
297
+ async buildEnd() {
298
+ const watchFiles = this.getWatchFiles();
299
+ debug?.("watchFiles count: ", watchFiles.length);
308
300
  const { build: build2 } = configResolved;
309
301
  const ignore = [
310
302
  ...defaultExcluded,
@@ -426,10 +418,8 @@ function vitePluginWeapp(ctx, subPackageMeta) {
426
418
  // console.log(id)
427
419
  // },
428
420
  // 调试监听
429
- buildEnd() {
430
- const watchFiles = this.getWatchFiles();
431
- debug?.("watchFiles count: ", watchFiles.length);
432
- },
421
+ // buildEnd() {
422
+ // },
433
423
  generateBundle(_options, bundle) {
434
424
  const bundleKeys = Object.keys(bundle);
435
425
  for (const bundleKey of bundleKeys) {
@@ -493,7 +483,6 @@ var CompilerContext = class {
493
483
  projectConfig;
494
484
  mode;
495
485
  packageJson;
496
- fsWatcherMap;
497
486
  rollupWatcherMap;
498
487
  entriesSet;
499
488
  entries;
@@ -514,7 +503,6 @@ var CompilerContext = class {
514
503
  this.projectConfig = projectConfig;
515
504
  this.mode = mode;
516
505
  this.packageJson = packageJson;
517
- this.fsWatcherMap = /* @__PURE__ */ new Map();
518
506
  this.rollupWatcherMap = /* @__PURE__ */ new Map();
519
507
  this.subPackageMeta = {};
520
508
  this.entriesSet = /* @__PURE__ */ new Set();
@@ -561,31 +549,7 @@ var CompilerContext = class {
561
549
  import_node_process.default.env.NODE_ENV = "development";
562
550
  }
563
551
  const inlineConfig = this.getConfig();
564
- const getWatcher = (paths2, opts2, inlineConfig2) => {
565
- const watcher2 = (0, import_chokidar.watch)(paths2, opts2);
566
- let isReady = false;
567
- watcher2.on("all", async (eventName, _p) => {
568
- if (isReady && (eventName === "add" || eventName === "change" || eventName === "unlink")) {
569
- await this.internalDev(inlineConfig2);
570
- }
571
- }).on("ready", async () => {
572
- await this.internalDev(inlineConfig2);
573
- isReady = true;
574
- });
575
- return watcher2;
576
- };
577
- const { paths, ...opts } = (0, import_shared2.defu)(
578
- inlineConfig.weapp?.watch,
579
- {
580
- ignored: [
581
- import_pathe5.default.join(this.mpDistRoot, "**")
582
- ],
583
- cwd: this.cwd
584
- },
585
- getWeappWatchOptions()
586
- );
587
- const watcher = getWatcher(paths, opts, inlineConfig);
588
- this.fsWatcherMap.set("/", watcher);
552
+ const watcher = await this.internalDev(inlineConfig);
589
553
  return watcher;
590
554
  }
591
555
  getConfig(subPackageMeta, ...configs) {
@@ -842,6 +806,9 @@ var CompilerContext = class {
842
806
  if (appEntryPath && await import_fs_extra6.default.exists(appConfigFile)) {
843
807
  const config = await readCommentJson(appConfigFile);
844
808
  if ((0, import_shared2.isObject)(config)) {
809
+ if (this.entriesSet.has(appEntryPath)) {
810
+ return;
811
+ }
845
812
  this.entriesSet.add(appEntryPath);
846
813
  const appEntry = {
847
814
  path: appEntryPath,
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  VERSION,
3
3
  createCompilerContext,
4
4
  logger_default
5
- } from "./chunk-BX3OGLVK.mjs";
5
+ } from "./chunk-MVHNNHNO.mjs";
6
6
  import "./chunk-444MQSSG.mjs";
7
7
 
8
8
  // src/cli.ts
@@ -1,5 +1,4 @@
1
1
  import { InlineConfig, UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
2
- import { WatchOptions as WatchOptions$1 } from 'chokidar';
3
2
  import { PackageJson } from 'pkg-types';
4
3
  import { Options } from 'tsup';
5
4
 
@@ -23,19 +22,12 @@ interface SubPackage {
23
22
  entry?: string;
24
23
  name?: string;
25
24
  }
26
- interface WatchOptions extends WatchOptions$1 {
27
- paths?: ReadonlyArray<string>;
28
- }
29
25
  interface WeappViteConfig {
30
26
  /**
31
27
  * @description 应用入口目录 (app.json 所在的目录)
32
28
  * 默认 js 模板在根目录,ts 模板在 miniprogram 目录
33
29
  */
34
30
  srcRoot?: string;
35
- /**
36
- * 覆盖默认 watch 行为
37
- */
38
- watch?: WatchOptions;
39
31
  /**
40
32
  * json 配置文件别名
41
33
  */
@@ -1,5 +1,4 @@
1
1
  import { InlineConfig, UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
2
- import { WatchOptions as WatchOptions$1 } from 'chokidar';
3
2
  import { PackageJson } from 'pkg-types';
4
3
  import { Options } from 'tsup';
5
4
 
@@ -23,19 +22,12 @@ interface SubPackage {
23
22
  entry?: string;
24
23
  name?: string;
25
24
  }
26
- interface WatchOptions extends WatchOptions$1 {
27
- paths?: ReadonlyArray<string>;
28
- }
29
25
  interface WeappViteConfig {
30
26
  /**
31
27
  * @description 应用入口目录 (app.json 所在的目录)
32
28
  * 默认 js 模板在根目录,ts 模板在 miniprogram 目录
33
29
  */
34
30
  srcRoot?: string;
35
- /**
36
- * 覆盖默认 watch 行为
37
- */
38
- watch?: WatchOptions;
39
31
  /**
40
32
  * json 配置文件别名
41
33
  */
package/dist/config.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { UserConfig, UserConfigExport, UserConfigFnObject } from 'vite';
2
- export { d as defineConfig } from './config-C5qVlm6D.cjs';
3
- import 'chokidar';
2
+ export { d as defineConfig } from './config-C1YqV4ix.cjs';
4
3
  import 'pkg-types';
5
4
  import 'tsup';
package/dist/config.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { UserConfig, UserConfigExport, UserConfigFnObject } from 'vite';
2
- export { d as defineConfig } from './config-C5qVlm6D.js';
3
- import 'chokidar';
2
+ export { d as defineConfig } from './config-C1YqV4ix.js';
4
3
  import 'pkg-types';
5
4
  import 'tsup';
package/dist/index.cjs CHANGED
@@ -43,7 +43,6 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
43
43
  var import_node_module = require("module");
44
44
  var import_node_process = __toESM(require("process"), 1);
45
45
  var import_shared2 = require("@weapp-core/shared");
46
- var import_chokidar = require("chokidar");
47
46
  var import_fs_extra6 = __toESM(require("fs-extra"), 1);
48
47
  var import_pathe5 = __toESM(require("pathe"), 1);
49
48
  var import_vite2 = require("vite");
@@ -51,15 +50,6 @@ var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
51
50
 
52
51
  // src/defaults.ts
53
52
  var defaultExcluded = ["**/node_modules/**", "**/miniprogram_npm/**"];
54
- function getWeappWatchOptions() {
55
- return {
56
- // '**/*.{wxml,json,wxs}', '**/*.{png,jpg,jpeg,gif,svg,webp}',
57
- paths: [".env", ".env.*"],
58
- ignored: [
59
- ...defaultExcluded
60
- ]
61
- };
62
- }
63
53
 
64
54
  // src/logger.ts
65
55
  var import_logger = __toESM(require("@weapp-core/logger"), 1);
@@ -306,7 +296,9 @@ function vitePluginWeapp(ctx, subPackageMeta) {
306
296
  const input = getInputOption([...entriesSet]);
307
297
  options.input = input;
308
298
  },
309
- async buildStart() {
299
+ async buildEnd() {
300
+ const watchFiles = this.getWatchFiles();
301
+ debug?.("watchFiles count: ", watchFiles.length);
310
302
  const { build: build2 } = configResolved;
311
303
  const ignore = [
312
304
  ...defaultExcluded,
@@ -428,10 +420,8 @@ function vitePluginWeapp(ctx, subPackageMeta) {
428
420
  // console.log(id)
429
421
  // },
430
422
  // 调试监听
431
- buildEnd() {
432
- const watchFiles = this.getWatchFiles();
433
- debug?.("watchFiles count: ", watchFiles.length);
434
- },
423
+ // buildEnd() {
424
+ // },
435
425
  generateBundle(_options, bundle) {
436
426
  const bundleKeys = Object.keys(bundle);
437
427
  for (const bundleKey of bundleKeys) {
@@ -495,7 +485,6 @@ var CompilerContext = class {
495
485
  projectConfig;
496
486
  mode;
497
487
  packageJson;
498
- fsWatcherMap;
499
488
  rollupWatcherMap;
500
489
  entriesSet;
501
490
  entries;
@@ -516,7 +505,6 @@ var CompilerContext = class {
516
505
  this.projectConfig = projectConfig;
517
506
  this.mode = mode;
518
507
  this.packageJson = packageJson;
519
- this.fsWatcherMap = /* @__PURE__ */ new Map();
520
508
  this.rollupWatcherMap = /* @__PURE__ */ new Map();
521
509
  this.subPackageMeta = {};
522
510
  this.entriesSet = /* @__PURE__ */ new Set();
@@ -563,31 +551,7 @@ var CompilerContext = class {
563
551
  import_node_process.default.env.NODE_ENV = "development";
564
552
  }
565
553
  const inlineConfig = this.getConfig();
566
- const getWatcher = (paths2, opts2, inlineConfig2) => {
567
- const watcher2 = (0, import_chokidar.watch)(paths2, opts2);
568
- let isReady = false;
569
- watcher2.on("all", async (eventName, _p) => {
570
- if (isReady && (eventName === "add" || eventName === "change" || eventName === "unlink")) {
571
- await this.internalDev(inlineConfig2);
572
- }
573
- }).on("ready", async () => {
574
- await this.internalDev(inlineConfig2);
575
- isReady = true;
576
- });
577
- return watcher2;
578
- };
579
- const { paths, ...opts } = (0, import_shared2.defu)(
580
- inlineConfig.weapp?.watch,
581
- {
582
- ignored: [
583
- import_pathe5.default.join(this.mpDistRoot, "**")
584
- ],
585
- cwd: this.cwd
586
- },
587
- getWeappWatchOptions()
588
- );
589
- const watcher = getWatcher(paths, opts, inlineConfig);
590
- this.fsWatcherMap.set("/", watcher);
554
+ const watcher = await this.internalDev(inlineConfig);
591
555
  return watcher;
592
556
  }
593
557
  getConfig(subPackageMeta, ...configs) {
@@ -844,6 +808,9 @@ var CompilerContext = class {
844
808
  if (appEntryPath && await import_fs_extra6.default.exists(appConfigFile)) {
845
809
  const config = await readCommentJson(appConfigFile);
846
810
  if ((0, import_shared2.isObject)(config)) {
811
+ if (this.entriesSet.has(appEntryPath)) {
812
+ return;
813
+ }
847
814
  this.entriesSet.add(appEntryPath);
848
815
  const appEntry = {
849
816
  path: appEntryPath,
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
- import { FSWatcher } from 'chokidar';
2
1
  import { PackageJson } from 'pkg-types';
3
- import { RollupOutput, RollupWatcher } from 'rollup';
4
- import { P as ProjectConfig, E as Entry, A as AppEntry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-C5qVlm6D.cjs';
2
+ import { RollupWatcher, RollupOutput } from 'rollup';
3
+ import { P as ProjectConfig, E as Entry, A as AppEntry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-C1YqV4ix.cjs';
5
4
  import { InlineConfig } from 'vite';
6
5
  import { Options } from 'tsup';
7
6
 
@@ -15,7 +14,6 @@ declare class CompilerContext {
15
14
  projectConfig: ProjectConfig;
16
15
  mode: string;
17
16
  packageJson: PackageJson;
18
- private fsWatcherMap;
19
17
  private rollupWatcherMap;
20
18
  entriesSet: Set<string>;
21
19
  entries: Entry[];
@@ -32,7 +30,7 @@ declare class CompilerContext {
32
30
  */
33
31
  get mpDistRoot(): string | undefined;
34
32
  private internalDev;
35
- runDev(): Promise<FSWatcher>;
33
+ runDev(): Promise<RollupWatcher>;
36
34
  getConfig(subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig>[]): InlineConfig;
37
35
  runProd(): Promise<RollupOutput | RollupOutput[]>;
38
36
  build(): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { FSWatcher } from 'chokidar';
2
1
  import { PackageJson } from 'pkg-types';
3
- import { RollupOutput, RollupWatcher } from 'rollup';
4
- import { P as ProjectConfig, E as Entry, A as AppEntry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-C5qVlm6D.js';
2
+ import { RollupWatcher, RollupOutput } from 'rollup';
3
+ import { P as ProjectConfig, E as Entry, A as AppEntry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-C1YqV4ix.js';
5
4
  import { InlineConfig } from 'vite';
6
5
  import { Options } from 'tsup';
7
6
 
@@ -15,7 +14,6 @@ declare class CompilerContext {
15
14
  projectConfig: ProjectConfig;
16
15
  mode: string;
17
16
  packageJson: PackageJson;
18
- private fsWatcherMap;
19
17
  private rollupWatcherMap;
20
18
  entriesSet: Set<string>;
21
19
  entries: Entry[];
@@ -32,7 +30,7 @@ declare class CompilerContext {
32
30
  */
33
31
  get mpDistRoot(): string | undefined;
34
32
  private internalDev;
35
- runDev(): Promise<FSWatcher>;
33
+ runDev(): Promise<RollupWatcher>;
36
34
  getConfig(subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig>[]): InlineConfig;
37
35
  runProd(): Promise<RollupOutput | RollupOutput[]>;
38
36
  build(): Promise<void>;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CompilerContext,
3
3
  createCompilerContext
4
- } from "./chunk-BX3OGLVK.mjs";
4
+ } from "./chunk-MVHNNHNO.mjs";
5
5
  import "./chunk-444MQSSG.mjs";
6
6
  export {
7
7
  CompilerContext,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-vite",
3
3
  "type": "module",
4
- "version": "1.5.6",
4
+ "version": "1.6.0",
5
5
  "description": "weapp-vite 一个现代化的小程序打包工具",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -52,7 +52,6 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "cac": "^6.7.14",
55
- "chokidar": "^3.6.0",
56
55
  "comment-json": "^4.2.5",
57
56
  "debug": "^4.3.7",
58
57
  "fdir": "^6.4.0",
@@ -63,10 +62,10 @@
63
62
  "tsup": "^8.3.0",
64
63
  "vite-tsconfig-paths": "^5.0.1",
65
64
  "@weapp-core/init": "^1.1.2",
66
- "@weapp-core/logger": "^1.0.1",
67
65
  "@weapp-core/schematics": "^1.0.1",
68
- "weapp-ide-cli": "^2.0.6",
69
- "@weapp-core/shared": "^1.0.3"
66
+ "@weapp-core/shared": "^1.0.3",
67
+ "@weapp-core/logger": "^1.0.1",
68
+ "weapp-ide-cli": "^2.0.6"
70
69
  },
71
70
  "publishConfig": {
72
71
  "access": "public",