weapp-vite 1.2.1 → 1.2.3

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.2.1";
6
+ var version = "1.2.3";
7
7
 
8
8
  // src/constants.ts
9
9
  var VERSION = version;
@@ -16,6 +16,7 @@ import { addExtension as addExtension3, defu as defu3, removeExtension as remove
16
16
  import { watch } from "chokidar";
17
17
  import fs4 from "fs-extra";
18
18
  import path5 from "pathe";
19
+ import { build as tsupBuild } from "tsup";
19
20
  import { build, loadConfigFromFile } from "vite";
20
21
  import tsconfigPaths from "vite-tsconfig-paths";
21
22
 
@@ -584,7 +585,9 @@ var CompilerContext = class _CompilerContext {
584
585
  mode: "development",
585
586
  plugins: [vitePluginWeapp(this)],
586
587
  build: {
587
- watch: {},
588
+ watch: {
589
+ exclude: ["node_modules/**", this.mpDistRoot ? path5.join(this.mpDistRoot, "**") : "dist/**"]
590
+ },
588
591
  minify: false,
589
592
  emptyOutDir: false
590
593
  },
@@ -652,10 +655,24 @@ var CompilerContext = class _CompilerContext {
652
655
  }
653
656
  }
654
657
  );
655
- const output = await build(
656
- inlineConfig
657
- );
658
- return output;
658
+ if (this.type === "subPackage" && this.subPackage) {
659
+ const subPackageInlineConfig = Object.assign({}, inlineConfig, {
660
+ weapp: {
661
+ srcRoot: this.parent?.srcRoot,
662
+ type: this.type,
663
+ subPackage: this.subPackage
664
+ }
665
+ });
666
+ const output = await build(
667
+ subPackageInlineConfig
668
+ );
669
+ return output;
670
+ } else if (this.type === "app") {
671
+ const output = await build(
672
+ inlineConfig
673
+ );
674
+ return output;
675
+ }
659
676
  }
660
677
  build() {
661
678
  if (this.isDev) {
@@ -707,9 +724,6 @@ var CompilerContext = class _CompilerContext {
707
724
  commonjsOptions: {
708
725
  transformMixedEsModules: true,
709
726
  include: void 0
710
- },
711
- watch: {
712
- exclude: ["node_modules/**", this.mpDistRoot ? path5.join(this.mpDistRoot, "**") : "dist/**"]
713
727
  }
714
728
  },
715
729
  logLevel: "info",
@@ -723,7 +737,8 @@ var CompilerContext = class _CompilerContext {
723
737
  // miniprogram_dist
724
738
  // miniprogram
725
739
  // https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B
726
- async buildNpm() {
740
+ async buildNpm(options) {
741
+ const { sourcemap } = defu3(options, { sourcemap: true });
727
742
  let packNpmRelationList = [];
728
743
  if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
729
744
  packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
@@ -756,25 +771,20 @@ var CompilerContext = class _CompilerContext {
756
771
  path5.join(outDir, dep)
757
772
  );
758
773
  } else {
759
- await build({
760
- build: {
761
- sourcemap: true,
762
- outDir: path5.join(outDir, dep),
763
- minify: false,
764
- rollupOptions: {
765
- input: {
766
- index: require2.resolve(dep)
767
- },
768
- output: {
769
- format: "cjs",
770
- strict: false,
771
- entryFileNames: "[name].js"
772
- }
773
- // logLevel: 'silent',
774
- },
775
- assetsDir: "."
774
+ await tsupBuild({
775
+ entry: {
776
+ index: require2.resolve(dep)
777
+ },
778
+ format: ["cjs"],
779
+ outDir: path5.join(outDir, dep),
780
+ silent: true,
781
+ shims: true,
782
+ outExtension: () => {
783
+ return {
784
+ js: ".js"
785
+ };
776
786
  },
777
- logLevel: "error"
787
+ sourcemap
778
788
  });
779
789
  }
780
790
  logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
package/dist/cli.cjs CHANGED
@@ -33,7 +33,7 @@ var import_cac = require("cac");
33
33
  var import_weapp_ide_cli = require("weapp-ide-cli");
34
34
 
35
35
  // package.json
36
- var version = "1.2.1";
36
+ var version = "1.2.3";
37
37
 
38
38
  // src/constants.ts
39
39
  var VERSION = version;
@@ -46,6 +46,7 @@ var import_shared4 = require("@weapp-core/shared");
46
46
  var import_chokidar = require("chokidar");
47
47
  var import_fs_extra4 = __toESM(require("fs-extra"), 1);
48
48
  var import_pathe5 = __toESM(require("pathe"), 1);
49
+ var import_tsup = require("tsup");
49
50
  var import_vite2 = require("vite");
50
51
  var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
51
52
 
@@ -618,7 +619,9 @@ var CompilerContext = class _CompilerContext {
618
619
  mode: "development",
619
620
  plugins: [vitePluginWeapp(this)],
620
621
  build: {
621
- watch: {},
622
+ watch: {
623
+ exclude: ["node_modules/**", this.mpDistRoot ? import_pathe5.default.join(this.mpDistRoot, "**") : "dist/**"]
624
+ },
622
625
  minify: false,
623
626
  emptyOutDir: false
624
627
  },
@@ -686,10 +689,24 @@ var CompilerContext = class _CompilerContext {
686
689
  }
687
690
  }
688
691
  );
689
- const output = await (0, import_vite2.build)(
690
- inlineConfig
691
- );
692
- return output;
692
+ if (this.type === "subPackage" && this.subPackage) {
693
+ const subPackageInlineConfig = Object.assign({}, inlineConfig, {
694
+ weapp: {
695
+ srcRoot: this.parent?.srcRoot,
696
+ type: this.type,
697
+ subPackage: this.subPackage
698
+ }
699
+ });
700
+ const output = await (0, import_vite2.build)(
701
+ subPackageInlineConfig
702
+ );
703
+ return output;
704
+ } else if (this.type === "app") {
705
+ const output = await (0, import_vite2.build)(
706
+ inlineConfig
707
+ );
708
+ return output;
709
+ }
693
710
  }
694
711
  build() {
695
712
  if (this.isDev) {
@@ -741,9 +758,6 @@ var CompilerContext = class _CompilerContext {
741
758
  commonjsOptions: {
742
759
  transformMixedEsModules: true,
743
760
  include: void 0
744
- },
745
- watch: {
746
- exclude: ["node_modules/**", this.mpDistRoot ? import_pathe5.default.join(this.mpDistRoot, "**") : "dist/**"]
747
761
  }
748
762
  },
749
763
  logLevel: "info",
@@ -757,7 +771,8 @@ var CompilerContext = class _CompilerContext {
757
771
  // miniprogram_dist
758
772
  // miniprogram
759
773
  // https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B
760
- async buildNpm() {
774
+ async buildNpm(options) {
775
+ const { sourcemap } = (0, import_shared4.defu)(options, { sourcemap: true });
761
776
  let packNpmRelationList = [];
762
777
  if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
763
778
  packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
@@ -790,25 +805,20 @@ var CompilerContext = class _CompilerContext {
790
805
  import_pathe5.default.join(outDir, dep)
791
806
  );
792
807
  } else {
793
- await (0, import_vite2.build)({
794
- build: {
795
- sourcemap: true,
796
- outDir: import_pathe5.default.join(outDir, dep),
797
- minify: false,
798
- rollupOptions: {
799
- input: {
800
- index: require2.resolve(dep)
801
- },
802
- output: {
803
- format: "cjs",
804
- strict: false,
805
- entryFileNames: "[name].js"
806
- }
807
- // logLevel: 'silent',
808
- },
809
- assetsDir: "."
808
+ await (0, import_tsup.build)({
809
+ entry: {
810
+ index: require2.resolve(dep)
811
+ },
812
+ format: ["cjs"],
813
+ outDir: import_pathe5.default.join(outDir, dep),
814
+ silent: true,
815
+ shims: true,
816
+ outExtension: () => {
817
+ return {
818
+ js: ".js"
819
+ };
810
820
  },
811
- logLevel: "error"
821
+ sourcemap
812
822
  });
813
823
  }
814
824
  logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
@@ -838,7 +848,7 @@ function convertBase(v) {
838
848
  cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
839
849
  type: [convertBase]
840
850
  }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
841
- cli.command("[root]", "start dev server").alias("serve").alias("dev").action(async (root, options) => {
851
+ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
842
852
  filterDuplicateOptions(options);
843
853
  const ctx = new CompilerContext({
844
854
  cwd: root,
@@ -846,7 +856,9 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").action(asy
846
856
  isDev: true
847
857
  });
848
858
  await ctx.loadDefaultConfig();
849
- await ctx.buildNpm();
859
+ if (!options.skipNpm) {
860
+ await ctx.buildNpm();
861
+ }
850
862
  await ctx.runDev();
851
863
  });
852
864
  cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
@@ -858,15 +870,17 @@ cli.command("build [root]", "build for production").option("--target <target>",
858
870
  ).option(
859
871
  "--emptyOutDir",
860
872
  `[boolean] force empty outDir when it's outside of root`
861
- ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).action(async (root, options) => {
873
+ ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
862
874
  filterDuplicateOptions(options);
863
875
  const ctx = new CompilerContext({
864
876
  cwd: root,
865
877
  mode: options.mode
866
878
  });
867
879
  await ctx.loadDefaultConfig();
868
- await ctx.buildNpm();
869
880
  await ctx.runProd();
881
+ if (!options.skipNpm) {
882
+ await ctx.buildNpm({ sourcemap: false });
883
+ }
870
884
  });
871
885
  cli.command("init").action(() => {
872
886
  try {
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  CompilerContext,
3
3
  VERSION,
4
4
  logger_default
5
- } from "./chunk-5SFYACIL.mjs";
5
+ } from "./chunk-MFE5RFWP.mjs";
6
6
  import "./chunk-444MQSSG.mjs";
7
7
 
8
8
  // src/cli.ts
@@ -27,7 +27,7 @@ function convertBase(v) {
27
27
  cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
28
28
  type: [convertBase]
29
29
  }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
30
- cli.command("[root]", "start dev server").alias("serve").alias("dev").action(async (root, options) => {
30
+ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
31
31
  filterDuplicateOptions(options);
32
32
  const ctx = new CompilerContext({
33
33
  cwd: root,
@@ -35,7 +35,9 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").action(asy
35
35
  isDev: true
36
36
  });
37
37
  await ctx.loadDefaultConfig();
38
- await ctx.buildNpm();
38
+ if (!options.skipNpm) {
39
+ await ctx.buildNpm();
40
+ }
39
41
  await ctx.runDev();
40
42
  });
41
43
  cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
@@ -47,15 +49,17 @@ cli.command("build [root]", "build for production").option("--target <target>",
47
49
  ).option(
48
50
  "--emptyOutDir",
49
51
  `[boolean] force empty outDir when it's outside of root`
50
- ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).action(async (root, options) => {
52
+ ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
51
53
  filterDuplicateOptions(options);
52
54
  const ctx = new CompilerContext({
53
55
  cwd: root,
54
56
  mode: options.mode
55
57
  });
56
58
  await ctx.loadDefaultConfig();
57
- await ctx.buildNpm();
58
59
  await ctx.runProd();
60
+ if (!options.skipNpm) {
61
+ await ctx.buildNpm({ sourcemap: false });
62
+ }
59
63
  });
60
64
  cli.command("init").action(() => {
61
65
  try {
package/dist/index.cjs CHANGED
@@ -45,6 +45,7 @@ var import_shared4 = require("@weapp-core/shared");
45
45
  var import_chokidar = require("chokidar");
46
46
  var import_fs_extra4 = __toESM(require("fs-extra"), 1);
47
47
  var import_pathe5 = __toESM(require("pathe"), 1);
48
+ var import_tsup = require("tsup");
48
49
  var import_vite2 = require("vite");
49
50
  var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
50
51
 
@@ -620,7 +621,9 @@ var CompilerContext = class _CompilerContext {
620
621
  mode: "development",
621
622
  plugins: [vitePluginWeapp(this)],
622
623
  build: {
623
- watch: {},
624
+ watch: {
625
+ exclude: ["node_modules/**", this.mpDistRoot ? import_pathe5.default.join(this.mpDistRoot, "**") : "dist/**"]
626
+ },
624
627
  minify: false,
625
628
  emptyOutDir: false
626
629
  },
@@ -688,10 +691,24 @@ var CompilerContext = class _CompilerContext {
688
691
  }
689
692
  }
690
693
  );
691
- const output = await (0, import_vite2.build)(
692
- inlineConfig
693
- );
694
- return output;
694
+ if (this.type === "subPackage" && this.subPackage) {
695
+ const subPackageInlineConfig = Object.assign({}, inlineConfig, {
696
+ weapp: {
697
+ srcRoot: this.parent?.srcRoot,
698
+ type: this.type,
699
+ subPackage: this.subPackage
700
+ }
701
+ });
702
+ const output = await (0, import_vite2.build)(
703
+ subPackageInlineConfig
704
+ );
705
+ return output;
706
+ } else if (this.type === "app") {
707
+ const output = await (0, import_vite2.build)(
708
+ inlineConfig
709
+ );
710
+ return output;
711
+ }
695
712
  }
696
713
  build() {
697
714
  if (this.isDev) {
@@ -743,9 +760,6 @@ var CompilerContext = class _CompilerContext {
743
760
  commonjsOptions: {
744
761
  transformMixedEsModules: true,
745
762
  include: void 0
746
- },
747
- watch: {
748
- exclude: ["node_modules/**", this.mpDistRoot ? import_pathe5.default.join(this.mpDistRoot, "**") : "dist/**"]
749
763
  }
750
764
  },
751
765
  logLevel: "info",
@@ -759,7 +773,8 @@ var CompilerContext = class _CompilerContext {
759
773
  // miniprogram_dist
760
774
  // miniprogram
761
775
  // https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B
762
- async buildNpm() {
776
+ async buildNpm(options) {
777
+ const { sourcemap } = (0, import_shared4.defu)(options, { sourcemap: true });
763
778
  let packNpmRelationList = [];
764
779
  if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
765
780
  packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
@@ -792,25 +807,20 @@ var CompilerContext = class _CompilerContext {
792
807
  import_pathe5.default.join(outDir, dep)
793
808
  );
794
809
  } else {
795
- await (0, import_vite2.build)({
796
- build: {
797
- sourcemap: true,
798
- outDir: import_pathe5.default.join(outDir, dep),
799
- minify: false,
800
- rollupOptions: {
801
- input: {
802
- index: require2.resolve(dep)
803
- },
804
- output: {
805
- format: "cjs",
806
- strict: false,
807
- entryFileNames: "[name].js"
808
- }
809
- // logLevel: 'silent',
810
- },
811
- assetsDir: "."
810
+ await (0, import_tsup.build)({
811
+ entry: {
812
+ index: require2.resolve(dep)
813
+ },
814
+ format: ["cjs"],
815
+ outDir: import_pathe5.default.join(outDir, dep),
816
+ silent: true,
817
+ shims: true,
818
+ outExtension: () => {
819
+ return {
820
+ js: ".js"
821
+ };
812
822
  },
813
- logLevel: "error"
823
+ sourcemap
814
824
  });
815
825
  }
816
826
  logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
package/dist/index.d.cts CHANGED
@@ -45,10 +45,12 @@ declare class CompilerContext {
45
45
  forkSubPackage(subPackage: SubPackage): CompilerContext;
46
46
  internalDev(inlineConfig: InlineConfig): Promise<RollupWatcher>;
47
47
  runDev(): Promise<FSWatcher | undefined>;
48
- runProd(): Promise<RollupOutput | RollupOutput[]>;
49
- build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[]>;
48
+ runProd(): Promise<RollupOutput | RollupOutput[] | undefined>;
49
+ build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[] | undefined>;
50
50
  loadDefaultConfig(): Promise<void>;
51
- buildNpm(): Promise<void>;
51
+ buildNpm(options?: {
52
+ sourcemap?: boolean;
53
+ }): Promise<void>;
52
54
  }
53
55
 
54
56
  export { CompilerContext, type CompilerContextOptions };
package/dist/index.d.ts CHANGED
@@ -45,10 +45,12 @@ declare class CompilerContext {
45
45
  forkSubPackage(subPackage: SubPackage): CompilerContext;
46
46
  internalDev(inlineConfig: InlineConfig): Promise<RollupWatcher>;
47
47
  runDev(): Promise<FSWatcher | undefined>;
48
- runProd(): Promise<RollupOutput | RollupOutput[]>;
49
- build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[]>;
48
+ runProd(): Promise<RollupOutput | RollupOutput[] | undefined>;
49
+ build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[] | undefined>;
50
50
  loadDefaultConfig(): Promise<void>;
51
- buildNpm(): Promise<void>;
51
+ buildNpm(options?: {
52
+ sourcemap?: boolean;
53
+ }): Promise<void>;
52
54
  }
53
55
 
54
56
  export { CompilerContext, type CompilerContextOptions };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CompilerContext
3
- } from "./chunk-5SFYACIL.mjs";
3
+ } from "./chunk-MFE5RFWP.mjs";
4
4
  import "./chunk-444MQSSG.mjs";
5
5
  export {
6
6
  CompilerContext
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-vite",
3
3
  "type": "module",
4
- "version": "1.2.1",
4
+ "version": "1.2.3",
5
5
  "description": "weapp-vite 一个现代化的小程序打包工具",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -53,6 +53,7 @@
53
53
  "cac": "^6.7.14",
54
54
  "chokidar": "^3.6.0",
55
55
  "debug": "^4.3.7",
56
+ "esbuild": "^0.24.0",
56
57
  "fast-glob": "^3.3.2",
57
58
  "fdir": "^6.3.0",
58
59
  "fs-extra": "^11.2.0",
@@ -62,10 +63,12 @@
62
63
  "pathe": "^1.1.2",
63
64
  "picocolors": "^1.1.0",
64
65
  "pkg-types": "^1.2.0",
66
+ "rollup": "^4.22.4",
67
+ "tsup": "^8.3.0",
65
68
  "vite-tsconfig-paths": "^5.0.1",
66
69
  "@weapp-core/init": "^1.0.4",
67
- "@weapp-core/logger": "^1.0.1",
68
70
  "@weapp-core/shared": "^1.0.1",
71
+ "@weapp-core/logger": "^1.0.1",
69
72
  "weapp-ide-cli": "^2.0.5"
70
73
  },
71
74
  "publishConfig": {