weapp-vite 1.9.2 → 2.0.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.
package/dist/cli.mjs CHANGED
@@ -2,11 +2,12 @@ import {
2
2
  VERSION,
3
3
  createCompilerContext,
4
4
  logger_default
5
- } from "./chunk-I36YQNJ7.mjs";
6
- import "./chunk-2FYXPWJ7.mjs";
5
+ } from "./chunk-EO33M7LR.mjs";
6
+ import "./chunk-5E4BX2PC.mjs";
7
7
  import {
8
+ __name,
8
9
  init_esm_shims
9
- } from "./chunk-WKC6OQ3Q.mjs";
10
+ } from "./chunk-3HVIVQUO.mjs";
10
11
 
11
12
  // src/cli.ts
12
13
  init_esm_shims();
@@ -27,6 +28,7 @@ import path from "pathe";
27
28
  function composePath(outDir, filename) {
28
29
  return `${outDir}${outDir ? "/" : ""}${filename}`;
29
30
  }
31
+ __name(composePath, "composePath");
30
32
  var defaultExtensions = {
31
33
  js: "js",
32
34
  json: "json",
@@ -36,6 +38,7 @@ var defaultExtensions = {
36
38
  function resolveExtension(extension) {
37
39
  return extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
38
40
  }
41
+ __name(resolveExtension, "resolveExtension");
39
42
  async function generate(options) {
40
43
  let { fileName, outDir, extensions, type, cwd } = defu(options, {
41
44
  // fileName: 'index',
@@ -49,7 +52,11 @@ async function generate(options) {
49
52
  fileName = path.basename(outDir);
50
53
  }
51
54
  const basepath = path.resolve(cwd, outDir);
52
- const targetFileTypes = ["js", "wxss", "json"];
55
+ const targetFileTypes = [
56
+ "js",
57
+ "wxss",
58
+ "json"
59
+ ];
53
60
  if (type !== "app") {
54
61
  targetFileTypes.push("wxml");
55
62
  }
@@ -80,8 +87,10 @@ async function generate(options) {
80
87
  }
81
88
  }
82
89
  }
90
+ __name(generate, "generate");
83
91
 
84
92
  // src/cli.ts
93
+ import "reflect-metadata";
85
94
  var cli = cac("weapp-vite");
86
95
  function loadConfig() {
87
96
  return loadConfigFromFile({
@@ -89,6 +98,7 @@ function loadConfig() {
89
98
  mode: "development"
90
99
  }, void 0, process2.cwd());
91
100
  }
101
+ __name(loadConfig, "loadConfig");
92
102
  var logBuildAppFinishOnlyShowOnce = false;
93
103
  function logBuildAppFinish() {
94
104
  if (!logBuildAppFinishOnlyShowOnce) {
@@ -98,6 +108,7 @@ function logBuildAppFinish() {
98
108
  logBuildAppFinishOnlyShowOnce = true;
99
109
  }
100
110
  }
111
+ __name(logBuildAppFinish, "logBuildAppFinish");
101
112
  function filterDuplicateOptions(options) {
102
113
  for (const [key, value] of Object.entries(options)) {
103
114
  if (Array.isArray(value)) {
@@ -105,56 +116,57 @@ function filterDuplicateOptions(options) {
105
116
  }
106
117
  }
107
118
  }
119
+ __name(filterDuplicateOptions, "filterDuplicateOptions");
108
120
  function convertBase(v) {
109
121
  if (v === 0) {
110
122
  return "";
111
123
  }
112
124
  return v;
113
125
  }
126
+ __name(convertBase, "convertBase");
114
127
  async function openIde() {
115
128
  try {
116
- await parse(["open", "-p"]);
129
+ await parse([
130
+ "open",
131
+ "-p"
132
+ ]);
117
133
  } catch (error) {
118
134
  logger_default.error(error);
119
135
  }
120
136
  }
137
+ __name(openIde, "openIde");
121
138
  cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
122
- type: [convertBase]
139
+ type: [
140
+ convertBase
141
+ ]
123
142
  }).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`);
124
143
  cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
125
144
  filterDuplicateOptions(options);
126
- const ctx = await createCompilerContext({
145
+ const { buildService, npmService } = await createCompilerContext({
127
146
  cwd: root,
128
147
  mode: options.mode,
129
148
  isDev: true
130
149
  });
131
- await ctx.build();
150
+ await buildService.build();
132
151
  if (!options.skipNpm) {
133
- await ctx.buildNpm(void 0, { sourcemap: true });
152
+ await npmService.build(void 0, {
153
+ sourcemap: true
154
+ });
134
155
  }
135
156
  logBuildAppFinish();
136
157
  if (options.open) {
137
158
  await openIde();
138
159
  }
139
160
  });
140
- cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
141
- "--sourcemap [output]",
142
- `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
143
- ).option(
144
- "--minify [minifier]",
145
- `[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
146
- ).option(
147
- "--emptyOutDir",
148
- `[boolean] force empty outDir when it's outside of root`
149
- ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
161
+ cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("--sourcemap [output]", `[boolean | "inline" | "hidden"] output source maps for build (default: false)`).option("--minify [minifier]", `[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`).option("--emptyOutDir", `[boolean] force empty outDir when it's outside of root`).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
150
162
  filterDuplicateOptions(options);
151
- const ctx = await createCompilerContext({
163
+ const { buildService, npmService } = await createCompilerContext({
152
164
  cwd: root,
153
165
  mode: options.mode
154
166
  });
155
- await ctx.build();
167
+ await buildService.build();
156
168
  if (!options.skipNpm) {
157
- await ctx.buildNpm();
169
+ await npmService.build();
158
170
  }
159
171
  logBuildAppFinish();
160
172
  if (options.open) {
@@ -175,7 +187,10 @@ cli.command("open").action(async () => {
175
187
  });
176
188
  cli.command("npm").alias("build:npm").alias("build-npm").action(async () => {
177
189
  try {
178
- await parse(["build-npm", "-p"]);
190
+ await parse([
191
+ "build-npm",
192
+ "-p"
193
+ ]);
179
194
  } catch (error) {
180
195
  logger_default.error(error);
181
196
  }
@@ -1,9 +1,34 @@
1
- import { InlineConfig, UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
2
- import { Theme, Sitemap, App, Page, Component } from '@weapp-core/schematics';
3
- import { PackageJson } from 'pkg-types';
1
+ import { UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
2
+ import { a as Resolver } from './types-dS68tjL6.js';
4
3
  import { Options } from 'tsup';
5
4
  import { PluginOptions } from 'vite-tsconfig-paths';
6
- import { a as Resolver } from './types-dS68tjL6.js';
5
+ import { Theme, Sitemap, App, Page, Component } from '@weapp-core/schematics';
6
+
7
+ interface BaseEntry {
8
+ path: string;
9
+ jsonPath?: string;
10
+ json?: object;
11
+ type: 'app' | 'page' | 'component' | (string & {});
12
+ }
13
+ type Entry = AppEntry | PageEntry | ComponentEntry;
14
+ interface AppEntry extends BaseEntry {
15
+ type: 'app';
16
+ themeJsonPath?: string;
17
+ themeJson?: Theme;
18
+ sitemapJsonPath?: string;
19
+ sitemapJson?: Sitemap;
20
+ json?: App;
21
+ }
22
+ interface PageEntry extends BaseEntry {
23
+ type: 'page';
24
+ templatePath: string;
25
+ json?: Page;
26
+ }
27
+ interface ComponentEntry extends BaseEntry {
28
+ type: 'component';
29
+ templatePath: string;
30
+ json?: Component;
31
+ }
7
32
 
8
33
  interface Alias {
9
34
  find: string | RegExp;
@@ -63,21 +88,20 @@ interface AutoImportComponents {
63
88
  globs?: string[];
64
89
  resolvers?: Resolver[];
65
90
  }
66
- interface ScanComponentItem {
67
- start: number;
68
- end: number;
69
- }
70
- type ComponentsMap = Record<string, ScanComponentItem[]>;
71
- interface ProcessWxmlOptions {
91
+ type EnhanceWxmlOptions = ScanWxmlOptions & HandleWxmlOptions;
92
+ interface ScanWxmlOptions {
72
93
  excludeComponent?: (tagName: string) => boolean;
73
94
  platform?: MpPlatform;
95
+ }
96
+ interface HandleWxmlOptions {
74
97
  removeComment?: boolean;
98
+ transformEvent?: boolean;
75
99
  }
76
100
  interface EnhanceOptions {
77
101
  /**
78
102
  * wxml 增强
79
103
  */
80
- wxml?: boolean | (Partial<Pick<ProcessWxmlOptions, 'removeComment' | 'excludeComponent'>>);
104
+ wxml?: boolean | (Partial<Omit<EnhanceWxmlOptions, 'platform'>>);
81
105
  /**
82
106
  * wxs 增强
83
107
  */
@@ -128,6 +152,12 @@ interface WeappViteConfig {
128
152
  * 默认情况下包括大部分的图片资源格式
129
153
  */
130
154
  copy?: CopyOptions;
155
+ /**
156
+ * 是否把扫描到的 wxml 添加到额外的 wxml 文件列表, 输出到最终的产物中
157
+ * @param wxmlFilePath
158
+ * @returns
159
+ */
160
+ isAdditionalWxml?: (wxmlFilePath: string) => boolean;
131
161
  /**
132
162
  * 编译目标平台
133
163
  */
@@ -137,31 +167,6 @@ interface WeappViteConfig {
137
167
  */
138
168
  enhance?: EnhanceOptions;
139
169
  }
140
- interface BaseEntry {
141
- path: string;
142
- jsonPath?: string;
143
- json?: object;
144
- type: 'app' | 'page' | 'component' | (string & {});
145
- }
146
- type Entry = AppEntry | PageEntry | ComponentEntry;
147
- interface AppEntry extends BaseEntry {
148
- type: 'app';
149
- themeJsonPath?: string;
150
- themeJson?: Theme;
151
- sitemapJsonPath?: string;
152
- sitemapJson?: Sitemap;
153
- json?: App;
154
- }
155
- interface PageEntry extends BaseEntry {
156
- type: 'page';
157
- templatePath: string;
158
- json?: Page;
159
- }
160
- interface ComponentEntry extends BaseEntry {
161
- type: 'component';
162
- templatePath: string;
163
- json?: Component;
164
- }
165
170
  interface ProjectConfig {
166
171
  miniprogramRoot?: string;
167
172
  srcMiniprogramRoot?: string;
@@ -173,15 +178,6 @@ interface ProjectConfig {
173
178
  }[];
174
179
  };
175
180
  }
176
- interface CompilerContextOptions {
177
- cwd: string;
178
- inlineConfig?: InlineConfig;
179
- isDev?: boolean;
180
- projectConfig?: ProjectConfig;
181
- mode?: string;
182
- packageJson?: PackageJson;
183
- platform?: MpPlatform;
184
- }
185
181
  interface SubPackageMetaValue {
186
182
  entriesSet: Set<string>;
187
183
  entries: Entry[];
@@ -198,4 +194,4 @@ declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
198
194
  declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
199
195
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
200
196
 
201
- export { type AppEntry as A, type CompilerContextOptions as C, type Entry as E, type MpPlatform as M, type ProjectConfig as P, type ResolvedAlias as R, type SubPackageMetaValue as S, type ComponentsMap as a, type SubPackage as b, defineConfig as d };
197
+ export { type AppEntry as A, type Entry as E, type MpPlatform as M, type ProjectConfig as P, type ResolvedAlias as R, type SubPackageMetaValue as S, type SubPackage as a, type ScanWxmlOptions as b, defineConfig as d };
@@ -1,9 +1,34 @@
1
- import { InlineConfig, UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
2
- import { Theme, Sitemap, App, Page, Component } from '@weapp-core/schematics';
3
- import { PackageJson } from 'pkg-types';
1
+ import { UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
2
+ import { a as Resolver } from './types-dS68tjL6.cjs';
4
3
  import { Options } from 'tsup';
5
4
  import { PluginOptions } from 'vite-tsconfig-paths';
6
- import { a as Resolver } from './types-dS68tjL6.cjs';
5
+ import { Theme, Sitemap, App, Page, Component } from '@weapp-core/schematics';
6
+
7
+ interface BaseEntry {
8
+ path: string;
9
+ jsonPath?: string;
10
+ json?: object;
11
+ type: 'app' | 'page' | 'component' | (string & {});
12
+ }
13
+ type Entry = AppEntry | PageEntry | ComponentEntry;
14
+ interface AppEntry extends BaseEntry {
15
+ type: 'app';
16
+ themeJsonPath?: string;
17
+ themeJson?: Theme;
18
+ sitemapJsonPath?: string;
19
+ sitemapJson?: Sitemap;
20
+ json?: App;
21
+ }
22
+ interface PageEntry extends BaseEntry {
23
+ type: 'page';
24
+ templatePath: string;
25
+ json?: Page;
26
+ }
27
+ interface ComponentEntry extends BaseEntry {
28
+ type: 'component';
29
+ templatePath: string;
30
+ json?: Component;
31
+ }
7
32
 
8
33
  interface Alias {
9
34
  find: string | RegExp;
@@ -63,21 +88,20 @@ interface AutoImportComponents {
63
88
  globs?: string[];
64
89
  resolvers?: Resolver[];
65
90
  }
66
- interface ScanComponentItem {
67
- start: number;
68
- end: number;
69
- }
70
- type ComponentsMap = Record<string, ScanComponentItem[]>;
71
- interface ProcessWxmlOptions {
91
+ type EnhanceWxmlOptions = ScanWxmlOptions & HandleWxmlOptions;
92
+ interface ScanWxmlOptions {
72
93
  excludeComponent?: (tagName: string) => boolean;
73
94
  platform?: MpPlatform;
95
+ }
96
+ interface HandleWxmlOptions {
74
97
  removeComment?: boolean;
98
+ transformEvent?: boolean;
75
99
  }
76
100
  interface EnhanceOptions {
77
101
  /**
78
102
  * wxml 增强
79
103
  */
80
- wxml?: boolean | (Partial<Pick<ProcessWxmlOptions, 'removeComment' | 'excludeComponent'>>);
104
+ wxml?: boolean | (Partial<Omit<EnhanceWxmlOptions, 'platform'>>);
81
105
  /**
82
106
  * wxs 增强
83
107
  */
@@ -128,6 +152,12 @@ interface WeappViteConfig {
128
152
  * 默认情况下包括大部分的图片资源格式
129
153
  */
130
154
  copy?: CopyOptions;
155
+ /**
156
+ * 是否把扫描到的 wxml 添加到额外的 wxml 文件列表, 输出到最终的产物中
157
+ * @param wxmlFilePath
158
+ * @returns
159
+ */
160
+ isAdditionalWxml?: (wxmlFilePath: string) => boolean;
131
161
  /**
132
162
  * 编译目标平台
133
163
  */
@@ -137,31 +167,6 @@ interface WeappViteConfig {
137
167
  */
138
168
  enhance?: EnhanceOptions;
139
169
  }
140
- interface BaseEntry {
141
- path: string;
142
- jsonPath?: string;
143
- json?: object;
144
- type: 'app' | 'page' | 'component' | (string & {});
145
- }
146
- type Entry = AppEntry | PageEntry | ComponentEntry;
147
- interface AppEntry extends BaseEntry {
148
- type: 'app';
149
- themeJsonPath?: string;
150
- themeJson?: Theme;
151
- sitemapJsonPath?: string;
152
- sitemapJson?: Sitemap;
153
- json?: App;
154
- }
155
- interface PageEntry extends BaseEntry {
156
- type: 'page';
157
- templatePath: string;
158
- json?: Page;
159
- }
160
- interface ComponentEntry extends BaseEntry {
161
- type: 'component';
162
- templatePath: string;
163
- json?: Component;
164
- }
165
170
  interface ProjectConfig {
166
171
  miniprogramRoot?: string;
167
172
  srcMiniprogramRoot?: string;
@@ -173,15 +178,6 @@ interface ProjectConfig {
173
178
  }[];
174
179
  };
175
180
  }
176
- interface CompilerContextOptions {
177
- cwd: string;
178
- inlineConfig?: InlineConfig;
179
- isDev?: boolean;
180
- projectConfig?: ProjectConfig;
181
- mode?: string;
182
- packageJson?: PackageJson;
183
- platform?: MpPlatform;
184
- }
185
181
  interface SubPackageMetaValue {
186
182
  entriesSet: Set<string>;
187
183
  entries: Entry[];
@@ -198,4 +194,4 @@ declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
198
194
  declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
199
195
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
200
196
 
201
- export { type AppEntry as A, type CompilerContextOptions as C, type Entry as E, type MpPlatform as M, type ProjectConfig as P, type ResolvedAlias as R, type SubPackageMetaValue as S, type ComponentsMap as a, type SubPackage as b, defineConfig as d };
197
+ export { type AppEntry as A, type Entry as E, type MpPlatform as M, type ProjectConfig as P, type ResolvedAlias as R, type SubPackageMetaValue as S, type SubPackage as a, type ScanWxmlOptions as b, defineConfig as d };
package/dist/config.cjs CHANGED
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,7 @@ module.exports = __toCommonJS(config_exports);
26
27
  function defineConfig(config) {
27
28
  return config;
28
29
  }
30
+ __name(defineConfig, "defineConfig");
29
31
  // Annotate the CommonJS export names for ESM import in node:
30
32
  0 && (module.exports = {
31
33
  defineConfig
package/dist/config.d.cts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { UserConfig, UserConfigExport, UserConfigFnObject } from 'vite';
2
- export { d as defineConfig } from './config-D__5C2s3.cjs';
3
- import '@weapp-core/schematics';
4
- import 'pkg-types';
2
+ export { d as defineConfig } from './config-DYSwq1ku.cjs';
3
+ import './types-dS68tjL6.cjs';
5
4
  import 'tsup';
6
5
  import 'vite-tsconfig-paths';
7
- import './types-dS68tjL6.cjs';
6
+ import '@weapp-core/schematics';
package/dist/config.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { UserConfig, UserConfigExport, UserConfigFnObject } from 'vite';
2
- export { d as defineConfig } from './config-YkkDB5_Y.js';
3
- import '@weapp-core/schematics';
4
- import 'pkg-types';
2
+ export { d as defineConfig } from './config-BM_dhf8V.js';
3
+ import './types-dS68tjL6.js';
5
4
  import 'tsup';
6
5
  import 'vite-tsconfig-paths';
7
- import './types-dS68tjL6.js';
6
+ import '@weapp-core/schematics';
package/dist/config.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineConfig
3
- } from "./chunk-2FYXPWJ7.mjs";
4
- import "./chunk-WKC6OQ3Q.mjs";
3
+ } from "./chunk-5E4BX2PC.mjs";
4
+ import "./chunk-3HVIVQUO.mjs";
5
5
  export {
6
6
  defineConfig
7
7
  };