weapp-vite 1.0.6 → 1.1.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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../dist/cli.cjs')
package/bin/weapp-vite.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('../dist/cli.cjs')
2
+ import '../dist/cli.mjs'
@@ -1,17 +1,21 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-3276ZVN4.mjs";
4
-
5
1
  // src/build.ts
6
- init_esm_shims();
7
2
  import process2 from "node:process";
8
- import { addExtension as addExtension3, defu as defu3, removeExtension as removeExtension3 } from "@weapp-core/shared";
3
+ import { defu as defu3 } from "@weapp-core/shared";
4
+ import path6 from "pathe";
5
+ import { watch } from "chokidar";
6
+ import { build } from "vite";
7
+
8
+ // src/symbols.ts
9
+ var RootRollupSymbol = Symbol("root-rollup");
10
+ var DevSymbol = Symbol("dev");
11
+
12
+ // src/defaults.ts
13
+ import { addExtension as addExtension3, removeExtension as removeExtension3 } from "@weapp-core/shared";
9
14
  import { readPackageJSON } from "pkg-types";
10
15
  import path5 from "pathe";
11
16
  import tsconfigPaths from "vite-tsconfig-paths";
12
17
 
13
18
  // src/plugins/index.ts
14
- init_esm_shims();
15
19
  import path4 from "pathe";
16
20
  import fs3 from "fs-extra";
17
21
  import MagicString from "magic-string";
@@ -19,15 +23,22 @@ import { addExtension as addExtension2, removeExtension as removeExtension2 } fr
19
23
  import { isCSSRequest, preprocessCSS } from "vite";
20
24
  import fg from "fast-glob";
21
25
 
22
- // src/utils/index.ts
23
- init_esm_shims();
24
-
25
26
  // src/utils/scan.ts
26
- init_esm_shims();
27
27
  import path from "pathe";
28
28
  import fs from "fs-extra";
29
29
  import { addExtension, defu, isObject, removeExtension } from "@weapp-core/shared";
30
- var defaultExcluded = ["**/node_modules/**", "**/miniprogram_npm/**"];
30
+ function parseJsonUseComponents(json) {
31
+ const deps = [];
32
+ if (isObject(json.usingComponents)) {
33
+ deps.push(...Object.values(json.usingComponents).map((x) => {
34
+ return {
35
+ path: x,
36
+ type: "component"
37
+ };
38
+ }));
39
+ }
40
+ return deps;
41
+ }
31
42
  function searchAppEntry(options) {
32
43
  const { formatPath, root } = defu(options, {
33
44
  formatPath: (x) => x
@@ -84,18 +95,6 @@ function searchPageEntry(wxmlPath) {
84
95
  }
85
96
  }
86
97
  }
87
- function parseJsonUseComponents(json) {
88
- const deps = [];
89
- if (isObject(json.usingComponents)) {
90
- deps.push(...Object.values(json.usingComponents).map((x) => {
91
- return {
92
- path: x,
93
- type: "component"
94
- };
95
- }));
96
- }
97
- return deps;
98
- }
99
98
  function getWxmlEntry(wxmlPath, formatPath) {
100
99
  const pageEntry = searchPageEntry(wxmlPath);
101
100
  if (pageEntry) {
@@ -132,7 +131,6 @@ function getWxmlEntry(wxmlPath, formatPath) {
132
131
  }
133
132
 
134
133
  // src/utils/projectConfig.ts
135
- init_esm_shims();
136
134
  import path2 from "pathe";
137
135
  import fs2 from "fs-extra";
138
136
  function getProjectConfig(root, options) {
@@ -166,7 +164,6 @@ var supportedCssLangs = ["wxss", "scss", "less", "sass", "styl"];
166
164
  var supportedCssExtensions = supportedCssLangs.map((x) => `.${x}`);
167
165
 
168
166
  // src/entry.ts
169
- init_esm_shims();
170
167
  import process from "node:process";
171
168
  import mm from "micromatch";
172
169
  import { defu as defu2 } from "@weapp-core/shared";
@@ -175,9 +172,6 @@ import klaw from "klaw";
175
172
  function createFilter(include, exclude, options) {
176
173
  const opts = defu2(options, {
177
174
  ignore: exclude
178
- // debug: true,
179
- // dot: true,
180
- // contains: true,
181
175
  });
182
176
  return function(id) {
183
177
  if (typeof id !== "string") {
@@ -291,7 +285,6 @@ async function getEntries(options) {
291
285
  }
292
286
 
293
287
  // src/debugger.ts
294
- init_esm_shims();
295
288
  import createDebug from "debug";
296
289
  function createDebugger(namespace) {
297
290
  const debug2 = createDebug(namespace);
@@ -301,7 +294,6 @@ function createDebugger(namespace) {
301
294
  }
302
295
 
303
296
  // src/plugins/parse.ts
304
- init_esm_shims();
305
297
  function parseRequest(id) {
306
298
  const [filename, rawQuery] = id.split(`?`, 2);
307
299
  const query = Object.fromEntries(new URLSearchParams(rawQuery));
@@ -326,18 +318,18 @@ function getRealPath(res) {
326
318
  return res.filename;
327
319
  }
328
320
  function vitePluginWeapp(ctx) {
329
- function getInputOption(entries) {
330
- return entries.reduce((acc, cur) => {
331
- acc[relative(cur)] = cur;
332
- return acc;
333
- }, {});
334
- }
335
321
  const stylesIds = /* @__PURE__ */ new Set();
336
322
  let configResolved;
337
323
  let entriesSet = /* @__PURE__ */ new Set();
338
324
  function relative(p) {
339
325
  return path4.relative(configResolved.root, p);
340
326
  }
327
+ function getInputOption(entries) {
328
+ return entries.reduce((acc, cur) => {
329
+ acc[relative(cur)] = cur;
330
+ return acc;
331
+ }, {});
332
+ }
341
333
  let appEntry;
342
334
  return [
343
335
  {
@@ -356,10 +348,10 @@ function vitePluginWeapp(ctx) {
356
348
  configResolved = config;
357
349
  },
358
350
  async options(options) {
359
- const { root, build, weapp } = configResolved;
351
+ const { root, build: build2, weapp } = configResolved;
360
352
  const entries = await getEntries({
361
353
  root,
362
- outDir: build.outDir,
354
+ outDir: build2.outDir,
363
355
  srcRoot: weapp?.srcRoot,
364
356
  subPackage: weapp?.subPackage
365
357
  });
@@ -404,7 +396,7 @@ function vitePluginWeapp(ctx) {
404
396
  }
405
397
  },
406
398
  async buildStart() {
407
- const { root, build, weapp } = configResolved;
399
+ const { root, build: build2, weapp } = configResolved;
408
400
  let cwd = root;
409
401
  const ignore = [
410
402
  ...defaultExcluded
@@ -420,7 +412,7 @@ function vitePluginWeapp(ctx) {
420
412
  }) : [];
421
413
  ignore.push(
422
414
  ...[
423
- `${build.outDir}/**`,
415
+ `${build2.outDir}/**`,
424
416
  ...ignoreSubPackage,
425
417
  "project.config.json",
426
418
  "project.private.config.json",
@@ -522,19 +514,24 @@ function vitePluginWeapp(ctx) {
522
514
  ];
523
515
  }
524
516
 
525
- // src/symbols.ts
526
- init_esm_shims();
527
- var RootRollupSymbol = Symbol("root-rollup");
528
- var DevSymbol = Symbol("dev");
529
-
530
- // src/build.ts
531
- async function getDefaultConfig(ctx) {
517
+ // src/defaults.ts
518
+ var defaultExcluded = ["**/node_modules/**", "**/miniprogram_npm/**"];
519
+ function getWeappWatchOptions() {
520
+ return {
521
+ paths: ["**/*.{wxml,json,wxs}", "**/*.{png,jpg,jpeg,gif,svg,webp}", ".env", ".env.*"],
522
+ ignored: [
523
+ ...defaultExcluded
524
+ ]
525
+ };
526
+ }
527
+ async function getDefaultViteConfig(ctx) {
532
528
  const localPackageJson = await readPackageJSON();
533
529
  const external = [];
534
530
  if (localPackageJson.dependencies) {
535
531
  external.push(...Object.keys(localPackageJson.dependencies));
536
532
  }
537
533
  return {
534
+ mode: ctx.options.mode,
538
535
  build: {
539
536
  rollupOptions: {
540
537
  output: {
@@ -564,26 +561,29 @@ async function getDefaultConfig(ctx) {
564
561
  vitePluginWeapp(ctx),
565
562
  tsconfigPaths()
566
563
  ]
567
- // logLevel: 'silent',
568
564
  };
569
565
  }
566
+
567
+ // src/build.ts
570
568
  async function runDev(ctx, options) {
571
- process2.env.NODE_ENV = "development";
572
- const { build } = await import("vite");
569
+ if (process2.env.NODE_ENV === void 0) {
570
+ process2.env.NODE_ENV = "development";
571
+ }
572
+ const inlineConfig = defu3(
573
+ options,
574
+ await getDefaultViteConfig(ctx),
575
+ {
576
+ mode: "development",
577
+ build: {
578
+ watch: {},
579
+ minify: false,
580
+ emptyOutDir: false
581
+ }
582
+ }
583
+ );
573
584
  async function innerDev() {
574
585
  const rollupWatcher = await build(
575
- defu3(
576
- options,
577
- await getDefaultConfig(ctx),
578
- {
579
- mode: "development",
580
- build: {
581
- watch: {},
582
- minify: false,
583
- emptyOutDir: false
584
- }
585
- }
586
- )
586
+ inlineConfig
587
587
  );
588
588
  const key = options?.weapp?.subPackage?.root || RootRollupSymbol;
589
589
  const watcher = ctx.watcherCache.get(key);
@@ -594,14 +594,13 @@ async function runDev(ctx, options) {
594
594
  if (options?.weapp?.subPackage) {
595
595
  return await innerDev();
596
596
  } else {
597
- const { watch } = await import("./chokidar-D7MR2KRX.mjs");
598
- const watcher = watch(["**/*.{wxml,json,wxs}", "**/*.{png,jpg,jpeg,gif,svg,webp}"], {
597
+ const { paths, ...opts } = defu3(inlineConfig.weapp?.watch, {
599
598
  ignored: [
600
- ...defaultExcluded,
601
- path5.join(ctx.mpRoot, "**")
599
+ path6.join(ctx.mpRoot, "**")
602
600
  ],
603
601
  cwd: ctx.cwd
604
- });
602
+ }, getWeappWatchOptions());
603
+ const watcher = watch(paths, opts);
605
604
  let isReady = false;
606
605
  watcher.on("all", async (eventName) => {
607
606
  if (isReady && (eventName === "add" || eventName === "change" || eventName === "unlink")) {
@@ -615,22 +614,21 @@ async function runDev(ctx, options) {
615
614
  }
616
615
  }
617
616
  async function runProd(ctx, options) {
618
- const { build } = await import("vite");
617
+ const inlineConfig = defu3(
618
+ options,
619
+ await getDefaultViteConfig(ctx),
620
+ {
621
+ mode: "production"
622
+ }
623
+ );
619
624
  const output = await build(
620
- defu3(
621
- options,
622
- await getDefaultConfig(ctx),
623
- {
624
- mode: "production"
625
- }
626
- )
625
+ inlineConfig
627
626
  );
628
627
  return output;
629
628
  }
630
629
 
631
630
  export {
632
631
  getProjectConfig,
633
- getDefaultConfig,
634
632
  runDev,
635
633
  runProd
636
634
  };