weapp-vite 1.3.0 → 1.3.1

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.3.0";
6
+ var version = "1.3.1";
7
7
 
8
8
  // src/constants.ts
9
9
  var VERSION = version;
@@ -35,7 +35,7 @@ function getWeappWatchOptions() {
35
35
 
36
36
  // src/plugins/index.ts
37
37
  import { addExtension as addExtension2, removeExtension as removeExtension2 } from "@weapp-core/shared";
38
- import fg from "fast-glob";
38
+ import { fdir as Fdir } from "fdir";
39
39
  import fs5 from "fs-extra";
40
40
  import MagicString from "magic-string";
41
41
  import path4 from "pathe";
@@ -55,7 +55,7 @@ import fs4 from "fs-extra";
55
55
  import path3 from "pathe";
56
56
 
57
57
  // src/utils/json.ts
58
- import { parse as parseJson } from "comment-json";
58
+ import { parse as parseJson, stringify } from "comment-json";
59
59
  import fs from "fs-extra";
60
60
  function parseCommentJson(json) {
61
61
  return parseJson(json, void 0, true);
@@ -67,6 +67,12 @@ async function readCommentJson(filepath) {
67
67
  logger_default.error(`\u6B8B\u7834\u7684JSON\u6587\u4EF6: ${filepath}`);
68
68
  }
69
69
  }
70
+ function stringifyJson(value) {
71
+ return stringify(value, void 0, 2);
72
+ }
73
+ function resolveJson(value) {
74
+ return stringifyJson(value);
75
+ }
70
76
 
71
77
  // src/utils/projectConfig.ts
72
78
  import fs2 from "fs-extra";
@@ -103,6 +109,12 @@ import fs3 from "fs-extra";
103
109
  import path2 from "pathe";
104
110
 
105
111
  // src/utils/index.ts
112
+ function isJsOrTs(name) {
113
+ if (typeof name === "string") {
114
+ return jsExtensions.some((x) => name.endsWith(`.${x}`));
115
+ }
116
+ return false;
117
+ }
106
118
  function changeFileExtension(filePath, extension) {
107
119
  if (typeof filePath !== "string") {
108
120
  throw new TypeError(`Expected \`filePath\` to be a string, got \`${typeof filePath}\`.`);
@@ -138,21 +150,15 @@ function parseRequest(id) {
138
150
  query
139
151
  };
140
152
  }
141
-
142
- // src/plugins/index.ts
143
- var debug = createDebugger("weapp-vite:plugin");
144
- function isJsOrTs(name) {
145
- if (typeof name === "string") {
146
- return jsExtensions.some((x) => name.endsWith(`.${x}`));
147
- }
148
- return false;
149
- }
150
- function getRealPath(res) {
153
+ function getCssRealPath(res) {
151
154
  if (res.query.wxss) {
152
155
  return changeFileExtension(res.filename, "wxss");
153
156
  }
154
157
  return res.filename;
155
158
  }
159
+
160
+ // src/plugins/index.ts
161
+ var debug = createDebugger("weapp-vite:plugin");
156
162
  function vitePluginWeapp(ctx) {
157
163
  let configResolved;
158
164
  function relative(p) {
@@ -183,8 +189,7 @@ function vitePluginWeapp(ctx) {
183
189
  options.input = input;
184
190
  },
185
191
  async buildStart() {
186
- const { root, build: build2 } = configResolved;
187
- const cwd = root;
192
+ const { build: build2 } = configResolved;
188
193
  const ignore = [
189
194
  ...defaultExcluded
190
195
  ];
@@ -198,26 +203,36 @@ function vitePluginWeapp(ctx) {
198
203
  "tsconfig.node.json"
199
204
  ]
200
205
  );
201
- const files = await fg(
202
- // 假如去 join root 就是返回 absolute
203
- [path4.join(ctx.srcRoot ?? "", "**/*.{wxml,json,wxs,png,jpg,jpeg,gif,svg,webp}")],
206
+ const relFiles = await new Fdir().withRelativePaths().globWithOptions(
207
+ [path4.join(ctx.srcRoot ?? "", "**/*.{wxml,wxs,png,jpg,jpeg,gif,svg,webp}")],
204
208
  {
205
- cwd,
206
- ignore,
207
- absolute: false
209
+ cwd: ctx.cwd,
210
+ ignore
208
211
  }
209
- );
210
- const relFiles = files;
212
+ ).crawl(ctx.cwd).withPromise();
211
213
  for (const file of relFiles) {
212
214
  const filepath = path4.resolve(ctx.cwd, file);
213
215
  this.addWatchFile(filepath);
214
- const isMedia = !/\.(?:wxml|json|wxs)$/.test(file);
216
+ const isMedia = !/\.(?:wxml|wxs)$/.test(file);
215
217
  this.emitFile({
216
218
  type: "asset",
217
219
  fileName: ctx.relativeSrcRoot(file),
218
220
  source: isMedia ? await fs5.readFile(filepath) : await fs5.readFile(filepath, "utf8")
219
221
  });
220
222
  }
223
+ for (const entry of ctx.entries) {
224
+ if (entry.jsonPath) {
225
+ this.addWatchFile(entry.jsonPath);
226
+ if (entry.json) {
227
+ const fileName = ctx.relativeSrcRoot(path4.relative(ctx.cwd, entry.jsonPath));
228
+ this.emitFile({
229
+ type: "asset",
230
+ fileName,
231
+ source: resolveJson(entry.json)
232
+ });
233
+ }
234
+ }
235
+ }
221
236
  },
222
237
  resolveId(source) {
223
238
  if (/\.wxss$/.test(source)) {
@@ -241,7 +256,7 @@ function vitePluginWeapp(ctx) {
241
256
  };
242
257
  } else if (isCSSRequest(id)) {
243
258
  const parsed = parseRequest(id);
244
- const realPath = getRealPath(parsed);
259
+ const realPath = getCssRealPath(parsed);
245
260
  if (await fs5.exists(realPath)) {
246
261
  const css = await fs5.readFile(realPath, "utf8");
247
262
  return {
@@ -287,7 +302,7 @@ function vitePluginWeapp(ctx) {
287
302
 
288
303
  // src/context.ts
289
304
  var require2 = createRequire(import.meta.url);
290
- var CompilerContext = class _CompilerContext {
305
+ var CompilerContext = class {
291
306
  inlineConfig;
292
307
  cwd;
293
308
  isDev;
@@ -337,20 +352,6 @@ var CompilerContext = class _CompilerContext {
337
352
  get mpDistRoot() {
338
353
  return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot || "";
339
354
  }
340
- forkSubPackage(subPackage) {
341
- const ctx = new _CompilerContext({
342
- cwd: this.cwd,
343
- isDev: this.isDev,
344
- projectConfig: this.projectConfig,
345
- inlineConfig: this.inlineConfig,
346
- type: "subPackage",
347
- mode: this.mode,
348
- subPackage
349
- });
350
- this.subPackageContextMap.set(subPackage.root, ctx);
351
- ctx.parent = this;
352
- return ctx;
353
- }
354
355
  async internalDev(inlineConfig) {
355
356
  const rollupWatcher = await build(
356
357
  inlineConfig
@@ -393,6 +394,8 @@ var CompilerContext = class _CompilerContext {
393
394
  }).on("ready", async () => {
394
395
  await this.internalDev(inlineConfig2);
395
396
  isReady = true;
397
+ logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u6267\u884C `npm run open` \u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177");
398
+ logger_default.success("\u6216\u8005\u4F7F\u7528\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55 (`project.config.json` \u6240\u5728\u76EE\u5F55) \u67E5\u770B\u6548\u679C");
396
399
  });
397
400
  return watcher;
398
401
  };
@@ -442,6 +445,7 @@ var CompilerContext = class _CompilerContext {
442
445
  }
443
446
  }
444
447
  );
448
+ inlineConfig.logLevel = "info";
445
449
  if (this.type === "subPackage" && this.subPackage) {
446
450
  const subPackageInlineConfig = Object.assign({}, inlineConfig, {
447
451
  weapp: {
@@ -513,7 +517,7 @@ var CompilerContext = class _CompilerContext {
513
517
  include: void 0
514
518
  }
515
519
  },
516
- logLevel: "info",
520
+ logLevel: "warn",
517
521
  plugins: [
518
522
  tsconfigPaths()
519
523
  ],
@@ -572,6 +576,7 @@ var CompilerContext = class _CompilerContext {
572
576
  };
573
577
  },
574
578
  sourcemap
579
+ // clean: false,
575
580
  });
576
581
  }
577
582
  logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
@@ -667,9 +672,15 @@ var CompilerContext = class _CompilerContext {
667
672
  }
668
673
  }
669
674
  };
675
+ async function createCompilerContext(options) {
676
+ const ctx = new CompilerContext(options);
677
+ await ctx.loadDefaultConfig();
678
+ return ctx;
679
+ }
670
680
 
671
681
  export {
672
682
  logger_default,
673
683
  VERSION,
674
- CompilerContext
684
+ CompilerContext,
685
+ createCompilerContext
675
686
  };
package/dist/cli.cjs CHANGED
@@ -32,7 +32,7 @@ var import_cac = require("cac");
32
32
  var import_weapp_ide_cli = require("weapp-ide-cli");
33
33
 
34
34
  // package.json
35
- var version = "1.3.0";
35
+ var version = "1.3.1";
36
36
 
37
37
  // src/constants.ts
38
38
  var VERSION = version;
@@ -68,7 +68,7 @@ var logger_default = import_logger.default;
68
68
 
69
69
  // src/plugins/index.ts
70
70
  var import_shared2 = require("@weapp-core/shared");
71
- var import_fast_glob = __toESM(require("fast-glob"), 1);
71
+ var import_fdir = require("fdir");
72
72
  var import_fs_extra5 = __toESM(require("fs-extra"), 1);
73
73
  var import_magic_string = __toESM(require("magic-string"), 1);
74
74
  var import_pathe4 = __toESM(require("pathe"), 1);
@@ -100,6 +100,12 @@ async function readCommentJson(filepath) {
100
100
  logger_default.error(`\u6B8B\u7834\u7684JSON\u6587\u4EF6: ${filepath}`);
101
101
  }
102
102
  }
103
+ function stringifyJson(value) {
104
+ return (0, import_comment_json.stringify)(value, void 0, 2);
105
+ }
106
+ function resolveJson(value) {
107
+ return stringifyJson(value);
108
+ }
103
109
 
104
110
  // src/utils/projectConfig.ts
105
111
  var import_fs_extra2 = __toESM(require("fs-extra"), 1);
@@ -136,6 +142,12 @@ var import_fs_extra3 = __toESM(require("fs-extra"), 1);
136
142
  var import_pathe2 = __toESM(require("pathe"), 1);
137
143
 
138
144
  // src/utils/index.ts
145
+ function isJsOrTs(name) {
146
+ if (typeof name === "string") {
147
+ return jsExtensions.some((x) => name.endsWith(`.${x}`));
148
+ }
149
+ return false;
150
+ }
139
151
  function changeFileExtension(filePath, extension) {
140
152
  if (typeof filePath !== "string") {
141
153
  throw new TypeError(`Expected \`filePath\` to be a string, got \`${typeof filePath}\`.`);
@@ -171,21 +183,15 @@ function parseRequest(id) {
171
183
  query
172
184
  };
173
185
  }
174
-
175
- // src/plugins/index.ts
176
- var debug = createDebugger("weapp-vite:plugin");
177
- function isJsOrTs(name) {
178
- if (typeof name === "string") {
179
- return jsExtensions.some((x) => name.endsWith(`.${x}`));
180
- }
181
- return false;
182
- }
183
- function getRealPath(res) {
186
+ function getCssRealPath(res) {
184
187
  if (res.query.wxss) {
185
188
  return changeFileExtension(res.filename, "wxss");
186
189
  }
187
190
  return res.filename;
188
191
  }
192
+
193
+ // src/plugins/index.ts
194
+ var debug = createDebugger("weapp-vite:plugin");
189
195
  function vitePluginWeapp(ctx) {
190
196
  let configResolved;
191
197
  function relative(p) {
@@ -216,8 +222,7 @@ function vitePluginWeapp(ctx) {
216
222
  options.input = input;
217
223
  },
218
224
  async buildStart() {
219
- const { root, build: build2 } = configResolved;
220
- const cwd = root;
225
+ const { build: build2 } = configResolved;
221
226
  const ignore = [
222
227
  ...defaultExcluded
223
228
  ];
@@ -231,26 +236,36 @@ function vitePluginWeapp(ctx) {
231
236
  "tsconfig.node.json"
232
237
  ]
233
238
  );
234
- const files = await (0, import_fast_glob.default)(
235
- // 假如去 join root 就是返回 absolute
236
- [import_pathe4.default.join(ctx.srcRoot ?? "", "**/*.{wxml,json,wxs,png,jpg,jpeg,gif,svg,webp}")],
239
+ const relFiles = await new import_fdir.fdir().withRelativePaths().globWithOptions(
240
+ [import_pathe4.default.join(ctx.srcRoot ?? "", "**/*.{wxml,wxs,png,jpg,jpeg,gif,svg,webp}")],
237
241
  {
238
- cwd,
239
- ignore,
240
- absolute: false
242
+ cwd: ctx.cwd,
243
+ ignore
241
244
  }
242
- );
243
- const relFiles = files;
245
+ ).crawl(ctx.cwd).withPromise();
244
246
  for (const file of relFiles) {
245
247
  const filepath = import_pathe4.default.resolve(ctx.cwd, file);
246
248
  this.addWatchFile(filepath);
247
- const isMedia = !/\.(?:wxml|json|wxs)$/.test(file);
249
+ const isMedia = !/\.(?:wxml|wxs)$/.test(file);
248
250
  this.emitFile({
249
251
  type: "asset",
250
252
  fileName: ctx.relativeSrcRoot(file),
251
253
  source: isMedia ? await import_fs_extra5.default.readFile(filepath) : await import_fs_extra5.default.readFile(filepath, "utf8")
252
254
  });
253
255
  }
256
+ for (const entry of ctx.entries) {
257
+ if (entry.jsonPath) {
258
+ this.addWatchFile(entry.jsonPath);
259
+ if (entry.json) {
260
+ const fileName = ctx.relativeSrcRoot(import_pathe4.default.relative(ctx.cwd, entry.jsonPath));
261
+ this.emitFile({
262
+ type: "asset",
263
+ fileName,
264
+ source: resolveJson(entry.json)
265
+ });
266
+ }
267
+ }
268
+ }
254
269
  },
255
270
  resolveId(source) {
256
271
  if (/\.wxss$/.test(source)) {
@@ -274,7 +289,7 @@ function vitePluginWeapp(ctx) {
274
289
  };
275
290
  } else if ((0, import_vite.isCSSRequest)(id)) {
276
291
  const parsed = parseRequest(id);
277
- const realPath = getRealPath(parsed);
292
+ const realPath = getCssRealPath(parsed);
278
293
  if (await import_fs_extra5.default.exists(realPath)) {
279
294
  const css = await import_fs_extra5.default.readFile(realPath, "utf8");
280
295
  return {
@@ -320,7 +335,7 @@ function vitePluginWeapp(ctx) {
320
335
 
321
336
  // src/context.ts
322
337
  var require2 = (0, import_node_module.createRequire)(importMetaUrl);
323
- var CompilerContext = class _CompilerContext {
338
+ var CompilerContext = class {
324
339
  inlineConfig;
325
340
  cwd;
326
341
  isDev;
@@ -370,20 +385,6 @@ var CompilerContext = class _CompilerContext {
370
385
  get mpDistRoot() {
371
386
  return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot || "";
372
387
  }
373
- forkSubPackage(subPackage) {
374
- const ctx = new _CompilerContext({
375
- cwd: this.cwd,
376
- isDev: this.isDev,
377
- projectConfig: this.projectConfig,
378
- inlineConfig: this.inlineConfig,
379
- type: "subPackage",
380
- mode: this.mode,
381
- subPackage
382
- });
383
- this.subPackageContextMap.set(subPackage.root, ctx);
384
- ctx.parent = this;
385
- return ctx;
386
- }
387
388
  async internalDev(inlineConfig) {
388
389
  const rollupWatcher = await (0, import_vite2.build)(
389
390
  inlineConfig
@@ -426,6 +427,8 @@ var CompilerContext = class _CompilerContext {
426
427
  }).on("ready", async () => {
427
428
  await this.internalDev(inlineConfig2);
428
429
  isReady = true;
430
+ logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u6267\u884C `npm run open` \u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177");
431
+ logger_default.success("\u6216\u8005\u4F7F\u7528\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55 (`project.config.json` \u6240\u5728\u76EE\u5F55) \u67E5\u770B\u6548\u679C");
429
432
  });
430
433
  return watcher;
431
434
  };
@@ -475,6 +478,7 @@ var CompilerContext = class _CompilerContext {
475
478
  }
476
479
  }
477
480
  );
481
+ inlineConfig.logLevel = "info";
478
482
  if (this.type === "subPackage" && this.subPackage) {
479
483
  const subPackageInlineConfig = Object.assign({}, inlineConfig, {
480
484
  weapp: {
@@ -546,7 +550,7 @@ var CompilerContext = class _CompilerContext {
546
550
  include: void 0
547
551
  }
548
552
  },
549
- logLevel: "info",
553
+ logLevel: "warn",
550
554
  plugins: [
551
555
  (0, import_vite_tsconfig_paths.default)()
552
556
  ],
@@ -605,6 +609,7 @@ var CompilerContext = class _CompilerContext {
605
609
  };
606
610
  },
607
611
  sourcemap
612
+ // clean: false,
608
613
  });
609
614
  }
610
615
  logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
@@ -700,6 +705,11 @@ var CompilerContext = class _CompilerContext {
700
705
  }
701
706
  }
702
707
  };
708
+ async function createCompilerContext(options) {
709
+ const ctx = new CompilerContext(options);
710
+ await ctx.loadDefaultConfig();
711
+ return ctx;
712
+ }
703
713
 
704
714
  // src/cli.ts
705
715
  var cli = (0, import_cac.cac)("weapp-vite");
@@ -721,12 +731,11 @@ cli.option("-c, --config <file>", `[string] use specified config file`).option("
721
731
  }).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`);
722
732
  cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
723
733
  filterDuplicateOptions(options);
724
- const ctx = new CompilerContext({
734
+ const ctx = await createCompilerContext({
725
735
  cwd: root,
726
736
  mode: options.mode,
727
737
  isDev: true
728
738
  });
729
- await ctx.loadDefaultConfig();
730
739
  if (!options.skipNpm) {
731
740
  await ctx.buildNpm();
732
741
  }
@@ -743,11 +752,10 @@ cli.command("build [root]", "build for production").option("--target <target>",
743
752
  `[boolean] force empty outDir when it's outside of root`
744
753
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
745
754
  filterDuplicateOptions(options);
746
- const ctx = new CompilerContext({
755
+ const ctx = await createCompilerContext({
747
756
  cwd: root,
748
757
  mode: options.mode
749
758
  });
750
- await ctx.loadDefaultConfig();
751
759
  await ctx.runProd();
752
760
  if (!options.skipNpm) {
753
761
  await ctx.buildNpm({ sourcemap: false });
package/dist/cli.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
- CompilerContext,
3
2
  VERSION,
3
+ createCompilerContext,
4
4
  logger_default
5
- } from "./chunk-K4VNFHJL.mjs";
5
+ } from "./chunk-JB72VL2I.mjs";
6
6
  import "./chunk-444MQSSG.mjs";
7
7
 
8
8
  // src/cli.ts
@@ -28,12 +28,11 @@ cli.option("-c, --config <file>", `[string] use specified config file`).option("
28
28
  }).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`);
29
29
  cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
30
30
  filterDuplicateOptions(options);
31
- const ctx = new CompilerContext({
31
+ const ctx = await createCompilerContext({
32
32
  cwd: root,
33
33
  mode: options.mode,
34
34
  isDev: true
35
35
  });
36
- await ctx.loadDefaultConfig();
37
36
  if (!options.skipNpm) {
38
37
  await ctx.buildNpm();
39
38
  }
@@ -50,11 +49,10 @@ cli.command("build [root]", "build for production").option("--target <target>",
50
49
  `[boolean] force empty outDir when it's outside of root`
51
50
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).action(async (root, options) => {
52
51
  filterDuplicateOptions(options);
53
- const ctx = new CompilerContext({
52
+ const ctx = await createCompilerContext({
54
53
  cwd: root,
55
54
  mode: options.mode
56
55
  });
57
- await ctx.loadDefaultConfig();
58
56
  await ctx.runProd();
59
57
  if (!options.skipNpm) {
60
58
  await ctx.buildNpm({ sourcemap: false });
package/dist/index.cjs CHANGED
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- CompilerContext: () => CompilerContext
33
+ CompilerContext: () => CompilerContext,
34
+ createCompilerContext: () => createCompilerContext
34
35
  });
35
36
  module.exports = __toCommonJS(src_exports);
36
37
 
@@ -66,7 +67,7 @@ var logger_default = import_logger.default;
66
67
 
67
68
  // src/plugins/index.ts
68
69
  var import_shared2 = require("@weapp-core/shared");
69
- var import_fast_glob = __toESM(require("fast-glob"), 1);
70
+ var import_fdir = require("fdir");
70
71
  var import_fs_extra5 = __toESM(require("fs-extra"), 1);
71
72
  var import_magic_string = __toESM(require("magic-string"), 1);
72
73
  var import_pathe4 = __toESM(require("pathe"), 1);
@@ -103,6 +104,12 @@ async function readCommentJson(filepath) {
103
104
  logger_default.error(`\u6B8B\u7834\u7684JSON\u6587\u4EF6: ${filepath}`);
104
105
  }
105
106
  }
107
+ function stringifyJson(value) {
108
+ return (0, import_comment_json.stringify)(value, void 0, 2);
109
+ }
110
+ function resolveJson(value) {
111
+ return stringifyJson(value);
112
+ }
106
113
 
107
114
  // src/utils/projectConfig.ts
108
115
  var import_fs_extra2 = __toESM(require("fs-extra"), 1);
@@ -139,6 +146,12 @@ var import_fs_extra3 = __toESM(require("fs-extra"), 1);
139
146
  var import_pathe2 = __toESM(require("pathe"), 1);
140
147
 
141
148
  // src/utils/index.ts
149
+ function isJsOrTs(name) {
150
+ if (typeof name === "string") {
151
+ return jsExtensions.some((x) => name.endsWith(`.${x}`));
152
+ }
153
+ return false;
154
+ }
142
155
  function changeFileExtension(filePath, extension) {
143
156
  if (typeof filePath !== "string") {
144
157
  throw new TypeError(`Expected \`filePath\` to be a string, got \`${typeof filePath}\`.`);
@@ -174,21 +187,15 @@ function parseRequest(id) {
174
187
  query
175
188
  };
176
189
  }
177
-
178
- // src/plugins/index.ts
179
- var debug = createDebugger("weapp-vite:plugin");
180
- function isJsOrTs(name) {
181
- if (typeof name === "string") {
182
- return jsExtensions.some((x) => name.endsWith(`.${x}`));
183
- }
184
- return false;
185
- }
186
- function getRealPath(res) {
190
+ function getCssRealPath(res) {
187
191
  if (res.query.wxss) {
188
192
  return changeFileExtension(res.filename, "wxss");
189
193
  }
190
194
  return res.filename;
191
195
  }
196
+
197
+ // src/plugins/index.ts
198
+ var debug = createDebugger("weapp-vite:plugin");
192
199
  function vitePluginWeapp(ctx) {
193
200
  let configResolved;
194
201
  function relative(p) {
@@ -219,8 +226,7 @@ function vitePluginWeapp(ctx) {
219
226
  options.input = input;
220
227
  },
221
228
  async buildStart() {
222
- const { root, build: build2 } = configResolved;
223
- const cwd = root;
229
+ const { build: build2 } = configResolved;
224
230
  const ignore = [
225
231
  ...defaultExcluded
226
232
  ];
@@ -234,26 +240,36 @@ function vitePluginWeapp(ctx) {
234
240
  "tsconfig.node.json"
235
241
  ]
236
242
  );
237
- const files = await (0, import_fast_glob.default)(
238
- // 假如去 join root 就是返回 absolute
239
- [import_pathe4.default.join(ctx.srcRoot ?? "", "**/*.{wxml,json,wxs,png,jpg,jpeg,gif,svg,webp}")],
243
+ const relFiles = await new import_fdir.fdir().withRelativePaths().globWithOptions(
244
+ [import_pathe4.default.join(ctx.srcRoot ?? "", "**/*.{wxml,wxs,png,jpg,jpeg,gif,svg,webp}")],
240
245
  {
241
- cwd,
242
- ignore,
243
- absolute: false
246
+ cwd: ctx.cwd,
247
+ ignore
244
248
  }
245
- );
246
- const relFiles = files;
249
+ ).crawl(ctx.cwd).withPromise();
247
250
  for (const file of relFiles) {
248
251
  const filepath = import_pathe4.default.resolve(ctx.cwd, file);
249
252
  this.addWatchFile(filepath);
250
- const isMedia = !/\.(?:wxml|json|wxs)$/.test(file);
253
+ const isMedia = !/\.(?:wxml|wxs)$/.test(file);
251
254
  this.emitFile({
252
255
  type: "asset",
253
256
  fileName: ctx.relativeSrcRoot(file),
254
257
  source: isMedia ? await import_fs_extra5.default.readFile(filepath) : await import_fs_extra5.default.readFile(filepath, "utf8")
255
258
  });
256
259
  }
260
+ for (const entry of ctx.entries) {
261
+ if (entry.jsonPath) {
262
+ this.addWatchFile(entry.jsonPath);
263
+ if (entry.json) {
264
+ const fileName = ctx.relativeSrcRoot(import_pathe4.default.relative(ctx.cwd, entry.jsonPath));
265
+ this.emitFile({
266
+ type: "asset",
267
+ fileName,
268
+ source: resolveJson(entry.json)
269
+ });
270
+ }
271
+ }
272
+ }
257
273
  },
258
274
  resolveId(source) {
259
275
  if (/\.wxss$/.test(source)) {
@@ -277,7 +293,7 @@ function vitePluginWeapp(ctx) {
277
293
  };
278
294
  } else if ((0, import_vite.isCSSRequest)(id)) {
279
295
  const parsed = parseRequest(id);
280
- const realPath = getRealPath(parsed);
296
+ const realPath = getCssRealPath(parsed);
281
297
  if (await import_fs_extra5.default.exists(realPath)) {
282
298
  const css = await import_fs_extra5.default.readFile(realPath, "utf8");
283
299
  return {
@@ -323,7 +339,7 @@ function vitePluginWeapp(ctx) {
323
339
 
324
340
  // src/context.ts
325
341
  var require2 = (0, import_node_module.createRequire)(importMetaUrl);
326
- var CompilerContext = class _CompilerContext {
342
+ var CompilerContext = class {
327
343
  inlineConfig;
328
344
  cwd;
329
345
  isDev;
@@ -373,20 +389,6 @@ var CompilerContext = class _CompilerContext {
373
389
  get mpDistRoot() {
374
390
  return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot || "";
375
391
  }
376
- forkSubPackage(subPackage) {
377
- const ctx = new _CompilerContext({
378
- cwd: this.cwd,
379
- isDev: this.isDev,
380
- projectConfig: this.projectConfig,
381
- inlineConfig: this.inlineConfig,
382
- type: "subPackage",
383
- mode: this.mode,
384
- subPackage
385
- });
386
- this.subPackageContextMap.set(subPackage.root, ctx);
387
- ctx.parent = this;
388
- return ctx;
389
- }
390
392
  async internalDev(inlineConfig) {
391
393
  const rollupWatcher = await (0, import_vite2.build)(
392
394
  inlineConfig
@@ -429,6 +431,8 @@ var CompilerContext = class _CompilerContext {
429
431
  }).on("ready", async () => {
430
432
  await this.internalDev(inlineConfig2);
431
433
  isReady = true;
434
+ logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u6267\u884C `npm run open` \u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177");
435
+ logger_default.success("\u6216\u8005\u4F7F\u7528\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55 (`project.config.json` \u6240\u5728\u76EE\u5F55) \u67E5\u770B\u6548\u679C");
432
436
  });
433
437
  return watcher;
434
438
  };
@@ -478,6 +482,7 @@ var CompilerContext = class _CompilerContext {
478
482
  }
479
483
  }
480
484
  );
485
+ inlineConfig.logLevel = "info";
481
486
  if (this.type === "subPackage" && this.subPackage) {
482
487
  const subPackageInlineConfig = Object.assign({}, inlineConfig, {
483
488
  weapp: {
@@ -549,7 +554,7 @@ var CompilerContext = class _CompilerContext {
549
554
  include: void 0
550
555
  }
551
556
  },
552
- logLevel: "info",
557
+ logLevel: "warn",
553
558
  plugins: [
554
559
  (0, import_vite_tsconfig_paths.default)()
555
560
  ],
@@ -608,6 +613,7 @@ var CompilerContext = class _CompilerContext {
608
613
  };
609
614
  },
610
615
  sourcemap
616
+ // clean: false,
611
617
  });
612
618
  }
613
619
  logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
@@ -703,7 +709,13 @@ var CompilerContext = class _CompilerContext {
703
709
  }
704
710
  }
705
711
  };
712
+ async function createCompilerContext(options) {
713
+ const ctx = new CompilerContext(options);
714
+ await ctx.loadDefaultConfig();
715
+ return ctx;
716
+ }
706
717
  // Annotate the CommonJS export names for ESM import in node:
707
718
  0 && (module.exports = {
708
- CompilerContext
719
+ CompilerContext,
720
+ createCompilerContext
709
721
  });
package/dist/index.d.cts CHANGED
@@ -50,7 +50,6 @@ declare class CompilerContext {
50
50
  get srcRoot(): string;
51
51
  relativeSrcRoot(p: string): string;
52
52
  get mpDistRoot(): string;
53
- forkSubPackage(subPackage: SubPackage): CompilerContext;
54
53
  private internalDev;
55
54
  runDev(): Promise<FSWatcher | undefined>;
56
55
  runProd(): Promise<RollupOutput | RollupOutput[] | undefined>;
@@ -63,5 +62,6 @@ declare class CompilerContext {
63
62
  scanAppEntry(): Promise<void>;
64
63
  scanComponentEntry(componentEntry: string, dirname: string): Promise<void>;
65
64
  }
65
+ declare function createCompilerContext(options?: CompilerContextOptions): Promise<CompilerContext>;
66
66
 
67
- export { CompilerContext, type CompilerContextOptions, type Entry };
67
+ export { CompilerContext, type CompilerContextOptions, type Entry, createCompilerContext };
package/dist/index.d.ts CHANGED
@@ -50,7 +50,6 @@ declare class CompilerContext {
50
50
  get srcRoot(): string;
51
51
  relativeSrcRoot(p: string): string;
52
52
  get mpDistRoot(): string;
53
- forkSubPackage(subPackage: SubPackage): CompilerContext;
54
53
  private internalDev;
55
54
  runDev(): Promise<FSWatcher | undefined>;
56
55
  runProd(): Promise<RollupOutput | RollupOutput[] | undefined>;
@@ -63,5 +62,6 @@ declare class CompilerContext {
63
62
  scanAppEntry(): Promise<void>;
64
63
  scanComponentEntry(componentEntry: string, dirname: string): Promise<void>;
65
64
  }
65
+ declare function createCompilerContext(options?: CompilerContextOptions): Promise<CompilerContext>;
66
66
 
67
- export { CompilerContext, type CompilerContextOptions, type Entry };
67
+ export { CompilerContext, type CompilerContextOptions, type Entry, createCompilerContext };
package/dist/index.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  import {
2
- CompilerContext
3
- } from "./chunk-K4VNFHJL.mjs";
2
+ CompilerContext,
3
+ createCompilerContext
4
+ } from "./chunk-JB72VL2I.mjs";
4
5
  import "./chunk-444MQSSG.mjs";
5
6
  export {
6
- CompilerContext
7
+ CompilerContext,
8
+ createCompilerContext
7
9
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-vite",
3
3
  "type": "module",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "description": "weapp-vite 一个现代化的小程序打包工具",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -54,26 +54,25 @@
54
54
  "chokidar": "^3.6.0",
55
55
  "comment-json": "^4.2.5",
56
56
  "debug": "^4.3.7",
57
- "fast-glob": "^3.3.2",
58
57
  "fdir": "^6.4.0",
59
58
  "fs-extra": "^11.2.0",
60
- "htmlparser2": "^9.1.0",
61
59
  "magic-string": "^0.30.11",
62
- "micromatch": "^4.0.8",
63
60
  "pathe": "^1.1.2",
64
- "picocolors": "^1.1.0",
65
- "pkg-types": "^1.2.0",
61
+ "picomatch": "^4.0.2",
66
62
  "tsup": "^8.3.0",
67
63
  "vite-tsconfig-paths": "^5.0.1",
64
+ "@weapp-core/init": "^1.0.5",
68
65
  "@weapp-core/logger": "^1.0.1",
69
- "weapp-ide-cli": "^2.0.6",
70
66
  "@weapp-core/shared": "^1.0.1",
71
- "@weapp-core/init": "^1.0.5"
67
+ "weapp-ide-cli": "^2.0.6"
72
68
  },
73
69
  "publishConfig": {
74
70
  "access": "public",
75
71
  "registry": "https://registry.npmjs.org"
76
72
  },
73
+ "devDependencies": {
74
+ "htmlparser2": "^9.1.0"
75
+ },
77
76
  "scripts": {
78
77
  "dev": "tsup --watch --sourcemap",
79
78
  "build": "tsup",