weapp-vite 1.1.7 → 1.2.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.
- package/dist/{chunk-2E5WYTKQ.mjs → chunk-5SFYACIL.mjs} +93 -39
- package/dist/cli.cjs +98 -43
- package/dist/cli.mjs +5 -8
- package/dist/index.cjs +95 -38
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
// src/logger.ts
|
|
2
|
+
import logger from "@weapp-core/logger";
|
|
3
|
+
var logger_default = logger;
|
|
4
|
+
|
|
1
5
|
// package.json
|
|
2
|
-
var version = "1.1
|
|
6
|
+
var version = "1.2.1";
|
|
3
7
|
|
|
4
8
|
// src/constants.ts
|
|
5
9
|
var VERSION = version;
|
|
6
10
|
var jsExtensions = ["js", "ts"];
|
|
7
11
|
|
|
8
12
|
// src/context.ts
|
|
13
|
+
import { createRequire } from "node:module";
|
|
9
14
|
import process2 from "node:process";
|
|
10
15
|
import { addExtension as addExtension3, defu as defu3, removeExtension as removeExtension3 } from "@weapp-core/shared";
|
|
11
16
|
import { watch } from "chokidar";
|
|
@@ -45,7 +50,7 @@ function createDebugger(namespace) {
|
|
|
45
50
|
// src/entry.ts
|
|
46
51
|
import process from "node:process";
|
|
47
52
|
import { defu as defu2 } from "@weapp-core/shared";
|
|
48
|
-
import
|
|
53
|
+
import { fdir as Fdir } from "fdir";
|
|
49
54
|
import mm from "micromatch";
|
|
50
55
|
import path3 from "pathe";
|
|
51
56
|
|
|
@@ -229,21 +234,15 @@ async function getEntries(options) {
|
|
|
229
234
|
type: "subPackageEntry"
|
|
230
235
|
});
|
|
231
236
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
{
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (entry) {
|
|
242
|
-
if (entry.type === "component") {
|
|
243
|
-
componentEntries.push(entry);
|
|
244
|
-
} else if (entry.type === "page") {
|
|
245
|
-
pageEntries.push(entry);
|
|
246
|
-
}
|
|
237
|
+
const files = await new Fdir().withFullPaths().filter(filter).crawl(path3.join(root, subPackageRoot)).withPromise();
|
|
238
|
+
for (const file of files) {
|
|
239
|
+
if (/\.wxml$/.test(file)) {
|
|
240
|
+
const entry = getWxmlEntry(file, formatPath);
|
|
241
|
+
if (entry) {
|
|
242
|
+
if (entry.type === "component") {
|
|
243
|
+
componentEntries.push(entry);
|
|
244
|
+
} else if (entry.type === "page") {
|
|
245
|
+
pageEntries.push(entry);
|
|
247
246
|
}
|
|
248
247
|
}
|
|
249
248
|
}
|
|
@@ -273,21 +272,15 @@ async function getEntries(options) {
|
|
|
273
272
|
);
|
|
274
273
|
const pageEntries = [];
|
|
275
274
|
const componentEntries = [];
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
{
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (entry) {
|
|
286
|
-
if (entry.type === "component") {
|
|
287
|
-
componentEntries.push(entry);
|
|
288
|
-
} else if (entry.type === "page") {
|
|
289
|
-
pageEntries.push(entry);
|
|
290
|
-
}
|
|
275
|
+
const files = await new Fdir().withFullPaths().filter(filter).crawl(path3.join(root, srcRoot)).withPromise();
|
|
276
|
+
for (const file of files) {
|
|
277
|
+
if (/\.wxml$/.test(file)) {
|
|
278
|
+
const entry = getWxmlEntry(file, formatPath);
|
|
279
|
+
if (entry) {
|
|
280
|
+
if (entry.type === "component") {
|
|
281
|
+
componentEntries.push(entry);
|
|
282
|
+
} else if (entry.type === "page") {
|
|
283
|
+
pageEntries.push(entry);
|
|
291
284
|
}
|
|
292
285
|
}
|
|
293
286
|
}
|
|
@@ -297,7 +290,6 @@ async function getEntries(options) {
|
|
|
297
290
|
pages: pageEntries,
|
|
298
291
|
components: componentEntries,
|
|
299
292
|
subPackages: subPackageDeps
|
|
300
|
-
// walkPathsSet,
|
|
301
293
|
};
|
|
302
294
|
}
|
|
303
295
|
}
|
|
@@ -511,6 +503,7 @@ function vitePluginWeapp(ctx) {
|
|
|
511
503
|
}
|
|
512
504
|
|
|
513
505
|
// src/context.ts
|
|
506
|
+
var require2 = createRequire(import.meta.url);
|
|
514
507
|
var CompilerContext = class _CompilerContext {
|
|
515
508
|
inlineConfig;
|
|
516
509
|
cwd;
|
|
@@ -556,12 +549,6 @@ var CompilerContext = class _CompilerContext {
|
|
|
556
549
|
get mpDistRoot() {
|
|
557
550
|
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot || "";
|
|
558
551
|
}
|
|
559
|
-
// get weappConfig() {
|
|
560
|
-
// return this.inlineConfig.weapp
|
|
561
|
-
// }
|
|
562
|
-
// get inlineSubPackageConfig() {
|
|
563
|
-
// return this.weappConfig?.subPackage
|
|
564
|
-
// }
|
|
565
552
|
forkSubPackage(subPackage) {
|
|
566
553
|
const ctx = new _CompilerContext({
|
|
567
554
|
cwd: this.cwd,
|
|
@@ -725,15 +712,82 @@ var CompilerContext = class _CompilerContext {
|
|
|
725
712
|
exclude: ["node_modules/**", this.mpDistRoot ? path5.join(this.mpDistRoot, "**") : "dist/**"]
|
|
726
713
|
}
|
|
727
714
|
},
|
|
715
|
+
logLevel: "info",
|
|
728
716
|
plugins: [
|
|
729
717
|
tsconfigPaths()
|
|
730
718
|
],
|
|
731
719
|
configFile: false
|
|
732
720
|
}, loaded?.config, this.inlineConfig);
|
|
733
721
|
}
|
|
722
|
+
// https://cn.vitejs.dev/guide/build.html#library-mode
|
|
723
|
+
// miniprogram_dist
|
|
724
|
+
// miniprogram
|
|
725
|
+
// 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() {
|
|
727
|
+
let packNpmRelationList = [];
|
|
728
|
+
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
729
|
+
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
730
|
+
} else {
|
|
731
|
+
packNpmRelationList = [
|
|
732
|
+
{
|
|
733
|
+
miniprogramNpmDistDir: ".",
|
|
734
|
+
packageJsonPath: "./package.json"
|
|
735
|
+
}
|
|
736
|
+
];
|
|
737
|
+
}
|
|
738
|
+
for (const relation of packNpmRelationList) {
|
|
739
|
+
const packageJsonPath = path5.resolve(this.cwd, relation.packageJsonPath);
|
|
740
|
+
if (await fs4.exists(packageJsonPath)) {
|
|
741
|
+
const pkgJson = await fs4.readJson(packageJsonPath);
|
|
742
|
+
const outDir = path5.resolve(this.cwd, relation.miniprogramNpmDistDir, "miniprogram_npm");
|
|
743
|
+
if (pkgJson.dependencies) {
|
|
744
|
+
const dependencies = Object.keys(pkgJson.dependencies);
|
|
745
|
+
if (dependencies.length > 0) {
|
|
746
|
+
for (const dep of dependencies) {
|
|
747
|
+
const id = `${dep}/package.json`;
|
|
748
|
+
const targetJson = require2(id);
|
|
749
|
+
if ("miniprogram" in targetJson && targetJson.miniprogram) {
|
|
750
|
+
const targetJsonPath = require2.resolve(id);
|
|
751
|
+
await fs4.copy(
|
|
752
|
+
path5.resolve(
|
|
753
|
+
path5.dirname(targetJsonPath),
|
|
754
|
+
targetJson.miniprogram
|
|
755
|
+
),
|
|
756
|
+
path5.join(outDir, dep)
|
|
757
|
+
);
|
|
758
|
+
} 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: "."
|
|
776
|
+
},
|
|
777
|
+
logLevel: "error"
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
734
787
|
};
|
|
735
788
|
|
|
736
789
|
export {
|
|
790
|
+
logger_default,
|
|
737
791
|
VERSION,
|
|
738
792
|
CompilerContext
|
|
739
793
|
};
|
package/dist/cli.cjs
CHANGED
|
@@ -22,6 +22,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
|
|
25
|
+
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.0.0_postcss@8.4.47_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
|
|
26
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
27
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
28
|
+
|
|
25
29
|
// src/cli.ts
|
|
26
30
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
27
31
|
var import_init = require("@weapp-core/init");
|
|
@@ -29,13 +33,14 @@ var import_cac = require("cac");
|
|
|
29
33
|
var import_weapp_ide_cli = require("weapp-ide-cli");
|
|
30
34
|
|
|
31
35
|
// package.json
|
|
32
|
-
var version = "1.1
|
|
36
|
+
var version = "1.2.1";
|
|
33
37
|
|
|
34
38
|
// src/constants.ts
|
|
35
39
|
var VERSION = version;
|
|
36
40
|
var jsExtensions = ["js", "ts"];
|
|
37
41
|
|
|
38
42
|
// src/context.ts
|
|
43
|
+
var import_node_module = require("module");
|
|
39
44
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
40
45
|
var import_shared4 = require("@weapp-core/shared");
|
|
41
46
|
var import_chokidar = require("chokidar");
|
|
@@ -55,6 +60,10 @@ function getWeappWatchOptions() {
|
|
|
55
60
|
};
|
|
56
61
|
}
|
|
57
62
|
|
|
63
|
+
// src/logger.ts
|
|
64
|
+
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
65
|
+
var logger_default = import_logger.default;
|
|
66
|
+
|
|
58
67
|
// src/plugins/index.ts
|
|
59
68
|
var import_shared3 = require("@weapp-core/shared");
|
|
60
69
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
@@ -75,7 +84,7 @@ function createDebugger(namespace) {
|
|
|
75
84
|
// src/entry.ts
|
|
76
85
|
var import_node_process = __toESM(require("process"), 1);
|
|
77
86
|
var import_shared2 = require("@weapp-core/shared");
|
|
78
|
-
var
|
|
87
|
+
var import_fdir = require("fdir");
|
|
79
88
|
var import_micromatch = __toESM(require("micromatch"), 1);
|
|
80
89
|
var import_pathe3 = __toESM(require("pathe"), 1);
|
|
81
90
|
|
|
@@ -259,21 +268,15 @@ async function getEntries(options) {
|
|
|
259
268
|
type: "subPackageEntry"
|
|
260
269
|
});
|
|
261
270
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
{
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (entry) {
|
|
272
|
-
if (entry.type === "component") {
|
|
273
|
-
componentEntries.push(entry);
|
|
274
|
-
} else if (entry.type === "page") {
|
|
275
|
-
pageEntries.push(entry);
|
|
276
|
-
}
|
|
271
|
+
const files = await new import_fdir.fdir().withFullPaths().filter(filter).crawl(import_pathe3.default.join(root, subPackageRoot)).withPromise();
|
|
272
|
+
for (const file of files) {
|
|
273
|
+
if (/\.wxml$/.test(file)) {
|
|
274
|
+
const entry = getWxmlEntry(file, formatPath);
|
|
275
|
+
if (entry) {
|
|
276
|
+
if (entry.type === "component") {
|
|
277
|
+
componentEntries.push(entry);
|
|
278
|
+
} else if (entry.type === "page") {
|
|
279
|
+
pageEntries.push(entry);
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
282
|
}
|
|
@@ -303,21 +306,15 @@ async function getEntries(options) {
|
|
|
303
306
|
);
|
|
304
307
|
const pageEntries = [];
|
|
305
308
|
const componentEntries = [];
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
{
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (entry) {
|
|
316
|
-
if (entry.type === "component") {
|
|
317
|
-
componentEntries.push(entry);
|
|
318
|
-
} else if (entry.type === "page") {
|
|
319
|
-
pageEntries.push(entry);
|
|
320
|
-
}
|
|
309
|
+
const files = await new import_fdir.fdir().withFullPaths().filter(filter).crawl(import_pathe3.default.join(root, srcRoot)).withPromise();
|
|
310
|
+
for (const file of files) {
|
|
311
|
+
if (/\.wxml$/.test(file)) {
|
|
312
|
+
const entry = getWxmlEntry(file, formatPath);
|
|
313
|
+
if (entry) {
|
|
314
|
+
if (entry.type === "component") {
|
|
315
|
+
componentEntries.push(entry);
|
|
316
|
+
} else if (entry.type === "page") {
|
|
317
|
+
pageEntries.push(entry);
|
|
321
318
|
}
|
|
322
319
|
}
|
|
323
320
|
}
|
|
@@ -327,7 +324,6 @@ async function getEntries(options) {
|
|
|
327
324
|
pages: pageEntries,
|
|
328
325
|
components: componentEntries,
|
|
329
326
|
subPackages: subPackageDeps
|
|
330
|
-
// walkPathsSet,
|
|
331
327
|
};
|
|
332
328
|
}
|
|
333
329
|
}
|
|
@@ -541,6 +537,7 @@ function vitePluginWeapp(ctx) {
|
|
|
541
537
|
}
|
|
542
538
|
|
|
543
539
|
// src/context.ts
|
|
540
|
+
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
544
541
|
var CompilerContext = class _CompilerContext {
|
|
545
542
|
inlineConfig;
|
|
546
543
|
cwd;
|
|
@@ -586,12 +583,6 @@ var CompilerContext = class _CompilerContext {
|
|
|
586
583
|
get mpDistRoot() {
|
|
587
584
|
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot || "";
|
|
588
585
|
}
|
|
589
|
-
// get weappConfig() {
|
|
590
|
-
// return this.inlineConfig.weapp
|
|
591
|
-
// }
|
|
592
|
-
// get inlineSubPackageConfig() {
|
|
593
|
-
// return this.weappConfig?.subPackage
|
|
594
|
-
// }
|
|
595
586
|
forkSubPackage(subPackage) {
|
|
596
587
|
const ctx = new _CompilerContext({
|
|
597
588
|
cwd: this.cwd,
|
|
@@ -755,18 +746,80 @@ var CompilerContext = class _CompilerContext {
|
|
|
755
746
|
exclude: ["node_modules/**", this.mpDistRoot ? import_pathe5.default.join(this.mpDistRoot, "**") : "dist/**"]
|
|
756
747
|
}
|
|
757
748
|
},
|
|
749
|
+
logLevel: "info",
|
|
758
750
|
plugins: [
|
|
759
751
|
(0, import_vite_tsconfig_paths.default)()
|
|
760
752
|
],
|
|
761
753
|
configFile: false
|
|
762
754
|
}, loaded?.config, this.inlineConfig);
|
|
763
755
|
}
|
|
756
|
+
// https://cn.vitejs.dev/guide/build.html#library-mode
|
|
757
|
+
// miniprogram_dist
|
|
758
|
+
// miniprogram
|
|
759
|
+
// 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() {
|
|
761
|
+
let packNpmRelationList = [];
|
|
762
|
+
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
763
|
+
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
764
|
+
} else {
|
|
765
|
+
packNpmRelationList = [
|
|
766
|
+
{
|
|
767
|
+
miniprogramNpmDistDir: ".",
|
|
768
|
+
packageJsonPath: "./package.json"
|
|
769
|
+
}
|
|
770
|
+
];
|
|
771
|
+
}
|
|
772
|
+
for (const relation of packNpmRelationList) {
|
|
773
|
+
const packageJsonPath = import_pathe5.default.resolve(this.cwd, relation.packageJsonPath);
|
|
774
|
+
if (await import_fs_extra4.default.exists(packageJsonPath)) {
|
|
775
|
+
const pkgJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
776
|
+
const outDir = import_pathe5.default.resolve(this.cwd, relation.miniprogramNpmDistDir, "miniprogram_npm");
|
|
777
|
+
if (pkgJson.dependencies) {
|
|
778
|
+
const dependencies = Object.keys(pkgJson.dependencies);
|
|
779
|
+
if (dependencies.length > 0) {
|
|
780
|
+
for (const dep of dependencies) {
|
|
781
|
+
const id = `${dep}/package.json`;
|
|
782
|
+
const targetJson = require2(id);
|
|
783
|
+
if ("miniprogram" in targetJson && targetJson.miniprogram) {
|
|
784
|
+
const targetJsonPath = require2.resolve(id);
|
|
785
|
+
await import_fs_extra4.default.copy(
|
|
786
|
+
import_pathe5.default.resolve(
|
|
787
|
+
import_pathe5.default.dirname(targetJsonPath),
|
|
788
|
+
targetJson.miniprogram
|
|
789
|
+
),
|
|
790
|
+
import_pathe5.default.join(outDir, dep)
|
|
791
|
+
);
|
|
792
|
+
} 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: "."
|
|
810
|
+
},
|
|
811
|
+
logLevel: "error"
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
764
821
|
};
|
|
765
822
|
|
|
766
|
-
// src/logger.ts
|
|
767
|
-
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
768
|
-
var logger_default = import_logger.default;
|
|
769
|
-
|
|
770
823
|
// src/cli.ts
|
|
771
824
|
var cli = (0, import_cac.cac)("weapp-vite");
|
|
772
825
|
function filterDuplicateOptions(options) {
|
|
@@ -793,6 +846,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").action(asy
|
|
|
793
846
|
isDev: true
|
|
794
847
|
});
|
|
795
848
|
await ctx.loadDefaultConfig();
|
|
849
|
+
await ctx.buildNpm();
|
|
796
850
|
await ctx.runDev();
|
|
797
851
|
});
|
|
798
852
|
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
|
|
@@ -811,6 +865,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
|
|
|
811
865
|
mode: options.mode
|
|
812
866
|
});
|
|
813
867
|
await ctx.loadDefaultConfig();
|
|
868
|
+
await ctx.buildNpm();
|
|
814
869
|
await ctx.runProd();
|
|
815
870
|
});
|
|
816
871
|
cli.command("init").action(() => {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CompilerContext,
|
|
3
|
-
VERSION
|
|
4
|
-
|
|
3
|
+
VERSION,
|
|
4
|
+
logger_default
|
|
5
|
+
} from "./chunk-5SFYACIL.mjs";
|
|
5
6
|
import "./chunk-444MQSSG.mjs";
|
|
6
7
|
|
|
7
8
|
// src/cli.ts
|
|
@@ -9,12 +10,6 @@ import process from "node:process";
|
|
|
9
10
|
import { initConfig } from "@weapp-core/init";
|
|
10
11
|
import { cac } from "cac";
|
|
11
12
|
import { parse } from "weapp-ide-cli";
|
|
12
|
-
|
|
13
|
-
// src/logger.ts
|
|
14
|
-
import logger from "@weapp-core/logger";
|
|
15
|
-
var logger_default = logger;
|
|
16
|
-
|
|
17
|
-
// src/cli.ts
|
|
18
13
|
var cli = cac("weapp-vite");
|
|
19
14
|
function filterDuplicateOptions(options) {
|
|
20
15
|
for (const [key, value] of Object.entries(options)) {
|
|
@@ -40,6 +35,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").action(asy
|
|
|
40
35
|
isDev: true
|
|
41
36
|
});
|
|
42
37
|
await ctx.loadDefaultConfig();
|
|
38
|
+
await ctx.buildNpm();
|
|
43
39
|
await ctx.runDev();
|
|
44
40
|
});
|
|
45
41
|
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
|
|
@@ -58,6 +54,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
|
|
|
58
54
|
mode: options.mode
|
|
59
55
|
});
|
|
60
56
|
await ctx.loadDefaultConfig();
|
|
57
|
+
await ctx.buildNpm();
|
|
61
58
|
await ctx.runProd();
|
|
62
59
|
});
|
|
63
60
|
cli.command("init").action(() => {
|
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,12 @@ __export(src_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
|
+
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.0.0_postcss@8.4.47_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
|
|
38
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
39
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
|
|
37
41
|
// src/context.ts
|
|
42
|
+
var import_node_module = require("module");
|
|
38
43
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
39
44
|
var import_shared4 = require("@weapp-core/shared");
|
|
40
45
|
var import_chokidar = require("chokidar");
|
|
@@ -54,6 +59,10 @@ function getWeappWatchOptions() {
|
|
|
54
59
|
};
|
|
55
60
|
}
|
|
56
61
|
|
|
62
|
+
// src/logger.ts
|
|
63
|
+
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
64
|
+
var logger_default = import_logger.default;
|
|
65
|
+
|
|
57
66
|
// src/plugins/index.ts
|
|
58
67
|
var import_shared3 = require("@weapp-core/shared");
|
|
59
68
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
@@ -77,7 +86,7 @@ function createDebugger(namespace) {
|
|
|
77
86
|
// src/entry.ts
|
|
78
87
|
var import_node_process = __toESM(require("process"), 1);
|
|
79
88
|
var import_shared2 = require("@weapp-core/shared");
|
|
80
|
-
var
|
|
89
|
+
var import_fdir = require("fdir");
|
|
81
90
|
var import_micromatch = __toESM(require("micromatch"), 1);
|
|
82
91
|
var import_pathe3 = __toESM(require("pathe"), 1);
|
|
83
92
|
|
|
@@ -261,21 +270,15 @@ async function getEntries(options) {
|
|
|
261
270
|
type: "subPackageEntry"
|
|
262
271
|
});
|
|
263
272
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
{
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (entry) {
|
|
274
|
-
if (entry.type === "component") {
|
|
275
|
-
componentEntries.push(entry);
|
|
276
|
-
} else if (entry.type === "page") {
|
|
277
|
-
pageEntries.push(entry);
|
|
278
|
-
}
|
|
273
|
+
const files = await new import_fdir.fdir().withFullPaths().filter(filter).crawl(import_pathe3.default.join(root, subPackageRoot)).withPromise();
|
|
274
|
+
for (const file of files) {
|
|
275
|
+
if (/\.wxml$/.test(file)) {
|
|
276
|
+
const entry = getWxmlEntry(file, formatPath);
|
|
277
|
+
if (entry) {
|
|
278
|
+
if (entry.type === "component") {
|
|
279
|
+
componentEntries.push(entry);
|
|
280
|
+
} else if (entry.type === "page") {
|
|
281
|
+
pageEntries.push(entry);
|
|
279
282
|
}
|
|
280
283
|
}
|
|
281
284
|
}
|
|
@@ -305,21 +308,15 @@ async function getEntries(options) {
|
|
|
305
308
|
);
|
|
306
309
|
const pageEntries = [];
|
|
307
310
|
const componentEntries = [];
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
{
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (entry) {
|
|
318
|
-
if (entry.type === "component") {
|
|
319
|
-
componentEntries.push(entry);
|
|
320
|
-
} else if (entry.type === "page") {
|
|
321
|
-
pageEntries.push(entry);
|
|
322
|
-
}
|
|
311
|
+
const files = await new import_fdir.fdir().withFullPaths().filter(filter).crawl(import_pathe3.default.join(root, srcRoot)).withPromise();
|
|
312
|
+
for (const file of files) {
|
|
313
|
+
if (/\.wxml$/.test(file)) {
|
|
314
|
+
const entry = getWxmlEntry(file, formatPath);
|
|
315
|
+
if (entry) {
|
|
316
|
+
if (entry.type === "component") {
|
|
317
|
+
componentEntries.push(entry);
|
|
318
|
+
} else if (entry.type === "page") {
|
|
319
|
+
pageEntries.push(entry);
|
|
323
320
|
}
|
|
324
321
|
}
|
|
325
322
|
}
|
|
@@ -329,7 +326,6 @@ async function getEntries(options) {
|
|
|
329
326
|
pages: pageEntries,
|
|
330
327
|
components: componentEntries,
|
|
331
328
|
subPackages: subPackageDeps
|
|
332
|
-
// walkPathsSet,
|
|
333
329
|
};
|
|
334
330
|
}
|
|
335
331
|
}
|
|
@@ -543,6 +539,7 @@ function vitePluginWeapp(ctx) {
|
|
|
543
539
|
}
|
|
544
540
|
|
|
545
541
|
// src/context.ts
|
|
542
|
+
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
546
543
|
var CompilerContext = class _CompilerContext {
|
|
547
544
|
inlineConfig;
|
|
548
545
|
cwd;
|
|
@@ -588,12 +585,6 @@ var CompilerContext = class _CompilerContext {
|
|
|
588
585
|
get mpDistRoot() {
|
|
589
586
|
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot || "";
|
|
590
587
|
}
|
|
591
|
-
// get weappConfig() {
|
|
592
|
-
// return this.inlineConfig.weapp
|
|
593
|
-
// }
|
|
594
|
-
// get inlineSubPackageConfig() {
|
|
595
|
-
// return this.weappConfig?.subPackage
|
|
596
|
-
// }
|
|
597
588
|
forkSubPackage(subPackage) {
|
|
598
589
|
const ctx = new _CompilerContext({
|
|
599
590
|
cwd: this.cwd,
|
|
@@ -757,12 +748,78 @@ var CompilerContext = class _CompilerContext {
|
|
|
757
748
|
exclude: ["node_modules/**", this.mpDistRoot ? import_pathe5.default.join(this.mpDistRoot, "**") : "dist/**"]
|
|
758
749
|
}
|
|
759
750
|
},
|
|
751
|
+
logLevel: "info",
|
|
760
752
|
plugins: [
|
|
761
753
|
(0, import_vite_tsconfig_paths.default)()
|
|
762
754
|
],
|
|
763
755
|
configFile: false
|
|
764
756
|
}, loaded?.config, this.inlineConfig);
|
|
765
757
|
}
|
|
758
|
+
// https://cn.vitejs.dev/guide/build.html#library-mode
|
|
759
|
+
// miniprogram_dist
|
|
760
|
+
// miniprogram
|
|
761
|
+
// 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() {
|
|
763
|
+
let packNpmRelationList = [];
|
|
764
|
+
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
765
|
+
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
766
|
+
} else {
|
|
767
|
+
packNpmRelationList = [
|
|
768
|
+
{
|
|
769
|
+
miniprogramNpmDistDir: ".",
|
|
770
|
+
packageJsonPath: "./package.json"
|
|
771
|
+
}
|
|
772
|
+
];
|
|
773
|
+
}
|
|
774
|
+
for (const relation of packNpmRelationList) {
|
|
775
|
+
const packageJsonPath = import_pathe5.default.resolve(this.cwd, relation.packageJsonPath);
|
|
776
|
+
if (await import_fs_extra4.default.exists(packageJsonPath)) {
|
|
777
|
+
const pkgJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
778
|
+
const outDir = import_pathe5.default.resolve(this.cwd, relation.miniprogramNpmDistDir, "miniprogram_npm");
|
|
779
|
+
if (pkgJson.dependencies) {
|
|
780
|
+
const dependencies = Object.keys(pkgJson.dependencies);
|
|
781
|
+
if (dependencies.length > 0) {
|
|
782
|
+
for (const dep of dependencies) {
|
|
783
|
+
const id = `${dep}/package.json`;
|
|
784
|
+
const targetJson = require2(id);
|
|
785
|
+
if ("miniprogram" in targetJson && targetJson.miniprogram) {
|
|
786
|
+
const targetJsonPath = require2.resolve(id);
|
|
787
|
+
await import_fs_extra4.default.copy(
|
|
788
|
+
import_pathe5.default.resolve(
|
|
789
|
+
import_pathe5.default.dirname(targetJsonPath),
|
|
790
|
+
targetJson.miniprogram
|
|
791
|
+
),
|
|
792
|
+
import_pathe5.default.join(outDir, dep)
|
|
793
|
+
);
|
|
794
|
+
} 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: "."
|
|
812
|
+
},
|
|
813
|
+
logLevel: "error"
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
766
823
|
};
|
|
767
824
|
// Annotate the CommonJS export names for ESM import in node:
|
|
768
825
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,13 @@ import { InlineConfig } from 'vite';
|
|
|
7
7
|
interface ProjectConfig {
|
|
8
8
|
miniprogramRoot?: string;
|
|
9
9
|
srcMiniprogramRoot?: string;
|
|
10
|
+
setting?: {
|
|
11
|
+
packNpmManually?: boolean;
|
|
12
|
+
packNpmRelationList?: {
|
|
13
|
+
packageJsonPath: string;
|
|
14
|
+
miniprogramNpmDistDir: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
interface CompilerContextOptions {
|
|
@@ -41,6 +48,7 @@ declare class CompilerContext {
|
|
|
41
48
|
runProd(): Promise<RollupOutput | RollupOutput[]>;
|
|
42
49
|
build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[]>;
|
|
43
50
|
loadDefaultConfig(): Promise<void>;
|
|
51
|
+
buildNpm(): Promise<void>;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export { CompilerContext, type CompilerContextOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,13 @@ import { InlineConfig } from 'vite';
|
|
|
7
7
|
interface ProjectConfig {
|
|
8
8
|
miniprogramRoot?: string;
|
|
9
9
|
srcMiniprogramRoot?: string;
|
|
10
|
+
setting?: {
|
|
11
|
+
packNpmManually?: boolean;
|
|
12
|
+
packNpmRelationList?: {
|
|
13
|
+
packageJsonPath: string;
|
|
14
|
+
miniprogramNpmDistDir: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
interface CompilerContextOptions {
|
|
@@ -41,6 +48,7 @@ declare class CompilerContext {
|
|
|
41
48
|
runProd(): Promise<RollupOutput | RollupOutput[]>;
|
|
42
49
|
build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[]>;
|
|
43
50
|
loadDefaultConfig(): Promise<void>;
|
|
51
|
+
buildNpm(): Promise<void>;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export { CompilerContext, type CompilerContextOptions };
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"description": "weapp-vite 一个现代化的小程序打包工具",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"chokidar": "^3.6.0",
|
|
55
55
|
"debug": "^4.3.7",
|
|
56
56
|
"fast-glob": "^3.3.2",
|
|
57
|
+
"fdir": "^6.3.0",
|
|
57
58
|
"fs-extra": "^11.2.0",
|
|
58
59
|
"htmlparser2": "^9.1.0",
|
|
59
|
-
"klaw": "^4.1.0",
|
|
60
60
|
"magic-string": "^0.30.11",
|
|
61
61
|
"micromatch": "^4.0.8",
|
|
62
62
|
"pathe": "^1.1.2",
|